Example #1
0
def callback_handler(update, context):
    user = update.effective_user
    callback_data = update.callback_query.data
    if callback_data == command_count:
        count = count_messages(user_id=user.id)
        text = f'у Вас {count} сообщений'
    elif callback_data == command_list:
        messages = list_messages(user_id=user.id, limit=5)
        text = '\n'.join([
            f'#{message_id}-{message_text}'
            for message_id, message_text in messages
        ])

    else:
        text = 'произошла ошибка'
    update.effective_message.reply_text(text=text)
Example #2
0
def callback_handler(update: Update, context: CallbackContext):
    user = update.effective_user
    callback_data = update.callback_query.data

    if callback_data == COMMAND_COUNT:
        count = count_messages(user_id=user.id)
        text = f'У вас {count} сообщений!'
    elif callback_data == COMMAND_LIST:
        messages = list_messages(user_id=user.id, limit=5)
        text = '\n\n'.join([
            f'#{message_id} - {message_text}'
            for message_id, message_text in messages
        ])
    else:
        text = 'Произошла ошибка'

    update.effective_message.reply_text(text=text, )
Example #3
0
    def on_message(self, body, message):
        response = None

        if body["query"] == "all_messages":
            response = list_messages()
        elif body["query"] == "user_messages":
            response = list_user_messages(body["user_id"])
        elif body["query"] == "search_messages":
            response = search_messages(body["search"])
        elif body["query"] == "post_message":
            response = post_message(body["user_id"], body["message"])

        if response is not None:
            response_prod = MessageResponseProducer(self.connection, messages_response_queue)
            response_prod.put_message(
                {"response": response, "message_id": body["message_id"]}, messages_response_exchange
            )
        message.ack()
Example #4
0
    def on_message(self, body, message):
        response = None

        if body['query'] == 'all_messages':
            response = list_messages()
        elif body['query'] == 'user_messages':
            response = list_user_messages(body['user_id'])
        elif body['query'] == 'search_messages':
            response = search_messages(body['search'])
        elif body['query'] == 'post_message':
            response = post_message(body['user_id'], body['message'])

        if response is not None:
            response_prod = MessageResponseProducer(self.connection,
                                                    messages_response_queue)
            response_prod.put_message(
                {
                    'response': response,
                    'message_id': body['message_id']
                }, messages_response_exchange)
        message.ack()
Example #5
0
def message_list():
    messages = list_messages()
    return jsonify({'count': len(messages), 'messages': messages})