Beispiel #1
0
def post_message():
    """
        Post a message to a room
        ---
        tags:
          - messages
        parameters:
          - in: body
            name: content
            required: true
            schema:
              type: object
              required:
                - room
                - author
                - text
              properties:
                room:
                  type: string
                  example: 'party-room'
                author:
                  type: string
                  nullable: true
                  example: 'Kenni'
                text:
                  type: string
                  example: 'Hello sam'

        responses:
          200:
            description: The message was successfully posted.
            schema:
              id: Message
  """

    data = request.get_json()
    if not data:
        return jsonify({'message': 'message must be valid JSON object'}), 400
    if not all([data.get('text'), data.get('room'), data.get('author')]):
        return jsonify({
            'message':
            'text, room, and author keys must be present and non-empty'
        }), 400

    db = get_db()

    message = {
        'text': str(data['text']),
        'room': str(data['room']),
        'author': str(data['author']),
    }
    message_result = events.trigger_message_post(db, message)

    return jsonify(message_result)
Beispiel #2
0
def post_message():
    """
        Post a message to a room
        ---
        tags:
          - messages
        parameters:
          - in: body
            name: content
            required: true
            schema:
              type: object
              required:
                - room
                - author
                - text
              properties:
                room:
                  type: string
                  example: 'party-room'
                author:
                  type: string
                  nullable: true
                  example: 'Kenni'
                text:
                  type: string
                  example: 'Hello sam'

        responses:
          200:
            description: The message was successfully posted.
            schema:
              id: Message
  """

    data = request.get_json()
    # room is allowed to be blank because "" is a room
    if not data or not data.get(
            'text') or data.get('room') is None or not data.get('author'):
        return jsonify({'message':
                        'text, room, and author keys are required'}), 400

    db = get_db()

    message = {
        'text': str(data['text']),
        'room': str(data['room']),
        'author': str(data['author']),
    }
    message_result = events.trigger_message_post(db, message)

    return jsonify(message_result)
Beispiel #3
0
def post_message():
    """
        Post a Bot
        ---
        tags:
          - messages 
        parameters:
          - in: query
            name: room
            schema:
              type: string
            description: the name of the room to post the message
          - in: query
            name: author 
            schema:
              type: string 
            description: the name of the message's author
          - in: query
            name: text 
            schema:
              type: string 
            description: the name of the message's text
        responses:
          200:
            description: The message was successfully posted. 
            schema:
              id: Message
  """

    if request.values['text'].strip() == "":
        return jsonify({}), 400
    db = get_db()
    message = dict(request.values)
    message_result = events.trigger_message_post(db, message)

    return jsonify(message_result)
Beispiel #4
0
def form_accept():
    message = dict(request.values)
    events.trigger_message_post(message)

    return redirect('/', code=302)