Ejemplo n.º 1
0
    def test_user_property(self, mocker, fake_user):
        bot = TululBot('TOKEN')
        mock_get_me = mocker.patch.object(bot,
                                          'get_me',
                                          autospec=True,
                                          return_value=fake_user)

        rv = bot.user

        assert rv == fake_user
        mock_get_me.assert_called_once_with()
Ejemplo n.º 2
0
    def test_create_is_reply_to_filter(self, mocker, fake_message_dict,
                                       fake_user_dict):
        fake_replied_message_dict = fake_message_dict.copy()

        fake_message = types.Message.de_json(fake_message_dict)
        fake_replied_message = types.Message.de_json(fake_replied_message_dict)

        bot_user = types.User.de_json(fake_user_dict)
        bot_message = 'Message text from bot goes here'
        fake_replied_message.text = bot_message
        fake_replied_message.from_user = bot_user
        fake_message.reply_to_message = fake_replied_message

        bot = TululBot('TOKEN')
        bot.user = bot_user

        assert bot.create_is_reply_to_filter(bot_message)(fake_message)
        assert not bot.create_is_reply_to_filter('foo bar')(fake_message)
Ejemplo n.º 3
0
import traceback

from flask import Flask, abort, request
app = Flask(__name__)
app.config.from_object('{}.config'.format(__name__))

from telebot import types  # noqa: E402

from tululbot.utils import TululBot  # noqa: E402
bot = TululBot(app.config['TELEGRAM_BOT_TOKEN'])  # Must be before importing commands

from tululbot import commands  # noqa


# Why do this? See https://core.telegram.org/bots/api#setwebhook
webhook_url_path = '/{}'.format(app.config['TELEGRAM_BOT_TOKEN'])
webhook_url_base = app.config['WEBHOOK_HOST']

app.logger.setLevel(app.config['LOG_LEVEL'])


@app.route(webhook_url_path, methods=['POST'])
def main():
    json_data = request.get_json(silent=True)
    if json_data is not None:
        update = types.Update.de_json(json_data)
        app.logger.debug('Get an update with id %s', update.update_id)
        if update.message is not None:
            bot.process_new_messages([update.message])
        return 'OK'
    else: