Esempio n. 1
0
async def update_logger(
    update: types.Update,
    descriptions: list = ['none'],
):
    dispatcher = Dispatcher.get_current()
    bot = dispatcher.bot
    url = ''
    if hasattr(update, 'chat') and update.chat.type != "private":
        # ~ url = update.url
        url = update.link('link', as_html=False)
    text = list()
    text.append(u" ".join([
        u" ".join([
            "\#" + d.replace('_', '\_').replace('.', '\.').replace('*', '\*')
            for d in descriptions
        ]),
        url,
    ]))
    text.append('```')
    text.append(json.dumps(update.to_python(), indent=2))
    text.append('```')
    await bot.send_message(
        bot.users['special']['log'],
        '\n'.join(text),
        disable_notification=True,
        parse_mode="MarkdownV2",
    )
Esempio n. 2
0
async def info_logger(
  update: types.Update,
  descriptions: list = ['none'],
):
  dispatcher = Dispatcher.get_current()
  bot = dispatcher.bot
  url = ''
  if hasattr(update, 'chat') and update.chat.type != "private":
    # ~ url = update.url
    url = update.link('link', as_html = False)
  text = list()
  text.append(
    u" ".join([
      u" ".join([escape_md("#" + d) for d in descriptions]),
      url,
    ])
  )
  text.append('')
  text.append('```')
  text.append(json.dumps(update.to_python(), indent=2))
  text.append('```')
  try:
    await bot.send_message(
      chat_id = bot.users['special']['info'],
      text = '\n'.join(text),
      disable_notification = True,
      parse_mode = "MarkdownV2",
    )
  except KeyError:
    logging.debug(key_error)
Esempio n. 3
0
async def dispatcher(request: web.Request) -> Any:
    update = Update(**await request.json())
    if update.message is not None:
        return await dispatch_msg(update.message)

    if update.callback_query is not None:
        return await dispatch_callback(update.callback_query)
Esempio n. 4
0
    async def webhook_handler(request: Request) -> Response:
        raw_update = await request.json()
        telegram_update = Update(**raw_update)

        try:
            await dp.process_update(telegram_update)
        finally:
            return Response(status_code=HTTP_200_OK)
Esempio n. 5
0
    async def on_pre_process_update(update: Update, _):
        if (not update.message) and (not update.callback_query):
            return

        sentry_sdk.set_user({
            'id': (update.message or update.callback_query).from_user.id,
            'update':
            update.to_python()
        })
Esempio n. 6
0
async def webhook_handler(
        update_raw: Dict[str, Any] = Body(...),
        dp: Dispatcher = Depends(bot_dispatcher),
) -> Response:
    """Set route /hook with POST method will trigger this method."""
    telegram_update = Update(**update_raw)
    Dispatcher.set_current(dp)
    Bot.set_current(dp.bot)
    await dp.process_update(telegram_update)
    return Response(status_code=HTTP_200_OK)
async def telegram_webhook(
        update_raw: Dict[str, Any] = Body(...),
        dp: Dispatcher = Depends(bot_dispatcher),
) -> Response:
    """
    Pass the new update (event from telegram) to bot dispatcher for processing.
    """
    telegram_update = Update(**update_raw)
    await dp.process_update(telegram_update)
    return Response(status_code=HTTP_200_OK)
Esempio n. 8
0
async def debug_logger(
    update: types.Update,
    error: str = 'none',
    exception: Exception = None,
):
    dispatcher = Dispatcher.get_current()
    bot = dispatcher.bot
    url = ''
    if hasattr(update, 'chat') and update.chat.type != "private":
        url = update.url
    text = list()
    text.append(u" ".join(["#" + str(error), str(url)]))
    text.append('')
    text.append(json.dumps(update.to_python(), indent=2))
    text.append('')
    text.append(u"Exception: {exception}".format(exception=exception))
    await bot.send_message(
        bot.users['special']['debug'],
        '\n'.join(text),
        disable_notification=True,
    )
Esempio n. 9
0
    async def on_pre_process_update(self, update: types.Update, data: dict):
        u = update.to_python()
        pprint(u)
        u.update({'_id': u['update_id']})
        await db.updates.insert_one(u)

        if update.callback_query:
            from_user = update.callback_query.from_user
            from_chat = update.callback_query.message.chat
        elif update.message:
            from_user = update.message.from_user
            from_chat = update.message.chat
        elif update.edited_message:
            from_user = update.edited_message.from_user
            from_chat = update.edited_message.chat

        data['user'] = await update_user(from_user)

        if from_chat.type == 'supergroup':
            chat = await update_chat(from_chat)

            data['chat'] = chat
Esempio n. 10
0
 async def on_pre_process_update(self, update: types.Update, data: dict):
     update.conf['_start'] = time.time()
     self.logger.debug(f"Received update [ID:{update.update_id}]")
Esempio n. 11
0
 async def on_pre_process_update(self, update: types.Update, data: dict):
     update.conf['_start'] = time.time()
     pass
Esempio n. 12
0
 async def on_pre_process_update(self, update: types.Update, data: dict):
     await data['repo'].log_update(update.message.from_user.id,
                                   update.as_json())
Esempio n. 13
0
 def __init__(self, incoming: dict, bot: Bot):
     self.incoming_dict = incoming
     self.bot = bot
     self.update = Update(**self.incoming_dict)