def adapt_channel_post(self, update: Update,
                           context: CallbackContext) -> None:
        """
        Method to modify :py:class:telegram.Update containing channel message,
        so that it can be handled a a normal received message. Dispatches modified update again.
        Args:
            update:
            context:

        Returns:

        """
        if update.channel_post:
            update.message = update.channel_post
            update.channel_post = None
        elif update.edited_channel_post:
            update.message = update.edited_channel_post
            update.edited_channel_post = None

        entities = update.message.parse_entities()
        for entity in entities:
            if entity.type == entity.MENTION and context.bot.username == entities[
                    entity][1:]:
                # Strip mention from message
                update.message.text = (
                    update.message.text[0:entity.offset] +
                    update.message.text[entity.offset +
                                        entity.length:]).strip()
                self.updater.dispatcher.process_update(update)
                return
Beispiel #2
0
    def create_update(self, json_obj):
        update_id = self._get_simple_field(json_obj, 'update_id')
        message = self.get_message(json_obj)
        edited_message = self.get_edited_message(json_obj)
        channel_post = self.get_channel_post(json_obj)
        edited_channel_post = self.get_edited_channel_post(json_obj)
        inline_query = self.get_inline_query(json_obj)
        chosen_inline_result = self.get_chosen_inline_result(json_obj)
        callback_query = self.get_callback_query(json_obj)

        update = Update(
            update_id=update_id
        )

        if message:
            update.message = message

        if edited_message:
            update.edited_message = edited_message

        if channel_post:
            update.channel_post = channel_post

        if edited_channel_post:
            update.edited_channel_post = edited_channel_post

        if inline_query:
            update.inline_query = inline_query

        if chosen_inline_result:
            update.chosen_inline_result = chosen_inline_result

        if callback_query:
            update.callback_query = callback_query

        return update