Ejemplo n.º 1
0
    def test_set_webhook(self, mocker):
        bot = TululBot('TOKEN')
        return_value = 'some return value'
        webhook_url = 'some url'
        mock_set_webhook = mocker.patch.object(bot._telebot, 'set_webhook',
                                               return_value=return_value, autospec=True)

        rv = bot.set_webhook(webhook_url)

        assert rv == return_value
        mock_set_webhook.assert_called_once_with(webhook_url)
Ejemplo n.º 2
0
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:
        abort(403)


@app.errorhandler(500)
def handle_uncaught_exception(error):  # pragma: no cover
    if app.config['TULULBOT_DEVEL_CHAT_ID']:
        chat_id = app.config['TULULBOT_DEVEL_CHAT_ID']
        bot.send_message(chat_id, traceback.format_exc())

    return 'OK'


if app.config['APP_ENV'] != 'development':  # pragma: no cover
    bot.set_webhook('{}{}'.format(webhook_url_base, webhook_url_path))
Ejemplo n.º 3
0
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:
        abort(403)


@app.errorhandler(500)
def handle_uncaught_exception(error):  # pragma: no cover
    if app.config['TULULBOT_DEVEL_CHAT_ID']:
        chat_id = app.config['TULULBOT_DEVEL_CHAT_ID']
        bot.send_message(chat_id, traceback.format_exc())

    return 'OK'


if app.config['APP_ENV'] != 'development':  # pragma: no cover
    bot.set_webhook('{}{}'.format(webhook_url_base, webhook_url_path))