当前位置: 首页>>代码示例>>Python>>正文


Python Message.de_json方法代码示例

本文整理汇总了Python中telegram.Message.de_json方法的典型用法代码示例。如果您正苦于以下问题:Python Message.de_json方法的具体用法?Python Message.de_json怎么用?Python Message.de_json使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在telegram.Message的用法示例。


在下文中一共展示了Message.de_json方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: de_json

# 需要导入模块: from telegram import Message [as 别名]
# 或者: from telegram.Message import de_json [as 别名]
    def de_json(data, bot):
        """
        Args:
            data (dict):
            bot (telegram.Bot):

        Returns:
            telegram.Update:
        """
        if not data:
            return None

        data = super(Update, Update).de_json(data, bot)

        data['message'] = Message.de_json(data.get('message'), bot)
        data['edited_message'] = Message.de_json(data.get('edited_message'), bot)
        data['inline_query'] = InlineQuery.de_json(data.get('inline_query'), bot)
        data['chosen_inline_result'] = ChosenInlineResult.de_json(
            data.get('chosen_inline_result'), bot)
        data['callback_query'] = CallbackQuery.de_json(data.get('callback_query'), bot)
        data['shipping_query'] = ShippingQuery.de_json(data.get('shipping_query'), bot)
        data['pre_checkout_query'] = PreCheckoutQuery.de_json(data.get('pre_checkout_query'), bot)
        data['channel_post'] = Message.de_json(data.get('channel_post'), bot)
        data['edited_channel_post'] = Message.de_json(data.get('edited_channel_post'), bot)

        return Update(**data)
开发者ID:KenOokamiHoro,项目名称:python-telegram-bot,代码行数:28,代码来源:update.py

示例2: _post_message

# 需要导入模块: from telegram import Message [as 别名]
# 或者: from telegram.Message import de_json [as 别名]
    def _post_message(url, data, kwargs, timeout=None, network_delay=2.):
        """Posts a message to the telegram servers.

        Returns:
            telegram.Message

        """
        if not data.get('chat_id'):
            raise TelegramError('Invalid chat_id')

        if kwargs.get('reply_to_message_id'):
            reply_to_message_id = kwargs.get('reply_to_message_id')
            data['reply_to_message_id'] = reply_to_message_id

        if kwargs.get('reply_markup'):
            reply_markup = kwargs.get('reply_markup')
            if isinstance(reply_markup, ReplyMarkup):
                data['reply_markup'] = reply_markup.to_json()
            else:
                data['reply_markup'] = reply_markup

        result = request.post(url, data, timeout=timeout,
                              network_delay=network_delay)

        if result is True:
            return result

        return Message.de_json(result)
开发者ID:sensitiveio,项目名称:python-telegram-bot,代码行数:30,代码来源:bot.py

示例3: decorator

# 需要导入模块: from telegram import Message [as 别名]
# 或者: from telegram.Message import de_json [as 别名]
        def decorator(self, *args, **kwargs):
            """
            decorator
            """
            url, data = func(self, *args, **kwargs)

            if not kwargs.get('chat_id'):
                raise TelegramError('Invalid chat_id.')

            if kwargs.get('reply_to_message_id'):
                reply_to_message_id = kwargs.get('reply_to_message_id')
                data['reply_to_message_id'] = reply_to_message_id

            if kwargs.get('reply_markup'):
                reply_markup = kwargs.get('reply_markup')
                if isinstance(reply_markup, ReplyMarkup):
                    data['reply_markup'] = reply_markup.to_json()
                else:
                    data['reply_markup'] = reply_markup

            json_data = Bot._requestUrl(url, 'POST', data=data)
            data = Bot._parseAndCheckTelegram(json_data)

            if data is True:
                return data

            return Message.de_json(data)
开发者ID:jacostag,项目名称:python-telegram-bot,代码行数:29,代码来源:bot.py

示例4: decorator

# 需要导入模块: from telegram import Message [as 别名]
# 或者: from telegram.Message import de_json [as 别名]
        def decorator(self, *args, **kwargs):
            url, data = func(self, *args, **kwargs)

            if kwargs.get('reply_to_message_id'):
                data['reply_to_message_id'] = \
                    kwargs.get('reply_to_message_id')

            if kwargs.get('disable_notification'):
                data['disable_notification'] = \
                    kwargs.get('disable_notification')

            if kwargs.get('reply_markup'):
                reply_markup = kwargs.get('reply_markup')
                if isinstance(reply_markup, ReplyMarkup):
                    data['reply_markup'] = reply_markup.to_json()
                else:
                    data['reply_markup'] = reply_markup

            result = request.post(url, data,
                                  timeout=kwargs.get('timeout'))

            if result is True:
                return result

            return Message.de_json(result)
开发者ID:Gurzo,项目名称:python-telegram-bot,代码行数:27,代码来源:bot.py

示例5: forwardMessage

# 需要导入模块: from telegram import Message [as 别名]
# 或者: from telegram.Message import de_json [as 别名]
    def forwardMessage(self, chat_id, from_chat_id, message_id):
        """Use this method to forward messages of any kind.

        Args:
          chat_id:
            Unique identifier for the message recipient — User or GroupChat id.
          from_chat_id:
            Unique identifier for the chat where the original message was sent
            — User or GroupChat id.
          message_id:
            Unique message identifier.

        Returns:
          A telegram.Message instance representing the message forwarded.
        """

        url = "%s/forwardMessage" % (self.base_url)

        if not self.__auth:
            raise TelegramError({"message": "API must be authenticated."})

        data = {}
        if chat_id:
            data["chat_id"] = chat_id
        if from_chat_id:
            data["from_chat_id"] = from_chat_id
        if message_id:
            data["message_id"] = message_id

        json_data = self._requestUrl(url, "POST", data=data)
        data = self._parseAndCheckTelegram(json_data.decode())

        return Message.de_json(data)
开发者ID:kalloc,项目名称:python-telegram-bot,代码行数:35,代码来源:bot.py

示例6: decorator

# 需要导入模块: from telegram import Message [as 别名]
# 或者: from telegram.Message import de_json [as 别名]
        def decorator(self, *args, **kwargs):
            """
            decorator
            """
            url, data = func(self, *args, **kwargs)

            if not data.get('chat_id'):
                raise TelegramError('Invalid chat_id')

            if kwargs.get('reply_to_message_id'):
                reply_to_message_id = kwargs.get('reply_to_message_id')
                data['reply_to_message_id'] = reply_to_message_id

            if kwargs.get('reply_markup'):
                reply_markup = kwargs.get('reply_markup')
                if isinstance(reply_markup, ReplyMarkup):
                    data['reply_markup'] = reply_markup.to_json()
                else:
                    data['reply_markup'] = reply_markup

            result = request.post(url, data)

            if result is True:
                return result

            return Message.de_json(result)
开发者ID:peczony,项目名称:python-telegram-bot,代码行数:28,代码来源:bot.py

示例7: de_json

# 需要导入模块: from telegram import Message [as 别名]
# 或者: from telegram.Message import de_json [as 别名]
    def de_json(data):
        if not data:
            return None

        data['from_user'] = User.de_json(data.get('from'))
        data['message'] = Message.de_json(data.get('message'))

        return CallbackQuery(**data)
开发者ID:AlexR1712,项目名称:python-telegram-bot,代码行数:10,代码来源:callbackquery.py

示例8: de_json

# 需要导入模块: from telegram import Message [as 别名]
# 或者: from telegram.Message import de_json [as 别名]
    def de_json(data):
        if 'message' in data:
            from telegram import Message
            message = Message.de_json(data['message'])
        else:
            message = None

        return Update(update_id=data.get('update_id', None),
                      message=message)
开发者ID:yosit,项目名称:kinnernet_bot,代码行数:11,代码来源:update.py

示例9: de_json

# 需要导入模块: from telegram import Message [as 别名]
# 或者: from telegram.Message import de_json [as 别名]
    def de_json(cls, data, bot):
        if not data:
            return None

        data = super(Update, cls).de_json(data, bot)

        data['message'] = Message.de_json(data.get('message'), bot)
        data['edited_message'] = Message.de_json(data.get('edited_message'), bot)
        data['inline_query'] = InlineQuery.de_json(data.get('inline_query'), bot)
        data['chosen_inline_result'] = ChosenInlineResult.de_json(
            data.get('chosen_inline_result'), bot)
        data['callback_query'] = CallbackQuery.de_json(data.get('callback_query'), bot)
        data['shipping_query'] = ShippingQuery.de_json(data.get('shipping_query'), bot)
        data['pre_checkout_query'] = PreCheckoutQuery.de_json(data.get('pre_checkout_query'), bot)
        data['channel_post'] = Message.de_json(data.get('channel_post'), bot)
        data['edited_channel_post'] = Message.de_json(data.get('edited_channel_post'), bot)

        return cls(**data)
开发者ID:ferisystem,项目名称:python-telegram-bot,代码行数:20,代码来源:update.py

示例10: de_json

# 需要导入模块: from telegram import Message [as 别名]
# 或者: from telegram.Message import de_json [as 别名]
    def de_json(data):
        """
        Args:
            data (dict):

        Returns:
            telegram.Update:
        """
        if not data:
            return None

        data['message'] = Message.de_json(data.get('message'))
        data['edited_message'] = Message.de_json(data.get('edited_message'))
        data['inline_query'] = InlineQuery.de_json(data.get('inline_query'))
        data['chosen_inline_result'] = ChosenInlineResult.de_json(data.get('chosen_inline_result'))
        data['callback_query'] = CallbackQuery.de_json(data.get('callback_query'))

        return Update(**data)
开发者ID:9kopb,项目名称:python-telegram-bot,代码行数:20,代码来源:update.py

示例11: de_json

# 需要导入模块: from telegram import Message [as 别名]
# 或者: from telegram.Message import de_json [as 别名]
    def de_json(cls, data, bot):
        if not data:
            return None

        data['photo'] = ChatPhoto.de_json(data.get('photo'), bot)
        from telegram import Message
        data['pinned_message'] = Message.de_json(data.get('pinned_message'), bot)

        return cls(bot=bot, **data)
开发者ID:noam09,项目名称:deluge-telegramer,代码行数:11,代码来源:chat.py

示例12: de_json

# 需要导入模块: from telegram import Message [as 别名]
# 或者: from telegram.Message import de_json [as 别名]
    def de_json(cls, data, bot):
        if not data:
            return None

        data = super(CallbackQuery, cls).de_json(data, bot)

        data['from_user'] = User.de_json(data.get('from'), bot)
        data['message'] = Message.de_json(data.get('message'), bot)

        return cls(bot=bot, **data)
开发者ID:noam09,项目名称:deluge-telegramer,代码行数:12,代码来源:callbackquery.py

示例13: sendPhoto

# 需要导入模块: from telegram import Message [as 别名]
# 或者: from telegram.Message import de_json [as 别名]
    def sendPhoto(self,
                  chat_id,
                  photo,
                  caption=None,
                  reply_to_message_id=None,
                  reply_markup=None):
        """Use this method to send photos.

        Args:
          chat_id:
            Unique identifier for the message recipient — User or GroupChat id.
          photo:
            Photo to send. You can either pass a file_id as String to resend a
            photo that is already on the Telegram servers, or upload a new
            photo using multipart/form-data.
          caption:
            Photo caption (may also be used when resending photos by file_id).
            [Optional]
          reply_to_message_id:
            If the message is a reply, ID of the original message. [Optional]
          reply_markup:
            Additional interface options. A JSON-serialized object for a custom
            reply keyboard, instructions to hide keyboard or to force a reply
            from the user. [Optional]

        Returns:
          A telegram.Message instance representing the message posted.
        """

        url = '%s/sendPhoto' % (self.base_url)

        if not self.__auth:
            raise TelegramError({'message': "API must be authenticated."})

        data = {'chat_id': chat_id,
                'photo': photo}

        if caption:
            data['caption'] = caption
        if reply_to_message_id:
            data['reply_to_message_id'] = reply_to_message_id
        if reply_markup:
            if isinstance(reply_markup, ReplyMarkup):
                data['reply_markup'] = reply_markup.to_json()
            else:
                data['reply_markup'] = reply_markup

        json_data = self._requestUrl(url, 'POST', data=data)
        data = self._parseAndCheckTelegram(json_data.content)

        return Message.de_json(data)
开发者ID:macrojames,项目名称:python-telegram-bot,代码行数:53,代码来源:bot.py

示例14: de_json

# 需要导入模块: from telegram import Message [as 别名]
# 或者: from telegram.Message import de_json [as 别名]
    def de_json(data):
        """
        Args:
            data (str):

        Returns:
            telegram.Update:
        """
        if not data:
            return None

        data["message"] = Message.de_json(data["message"])

        return Update(**data)
开发者ID:jgrondier,项目名称:python-telegram-bot,代码行数:16,代码来源:update.py

示例15: sendMessage

# 需要导入模块: from telegram import Message [as 别名]
# 或者: from telegram.Message import de_json [as 别名]
    def sendMessage(self,
                    chat_id,
                    text,
                    disable_web_page_preview=None,
                    reply_to_message_id=None,
                    reply_markup=None):
        """Use this method to send text messages.

        Args:
          chat_id:
            Unique identifier for the message recipient — telegram.User or
            telegram.GroupChat id.
          text:
            Text of the message to be sent.
          disable_web_page_preview:
            Disables link previews for links in this message. [Optional]
          reply_to_message_id:
            If the message is a reply, ID of the original message. [Optional]
          reply_markup:
            Additional interface options. A JSON-serialized object for a custom
            reply keyboard, instructions to hide keyboard or to force a reply
            from the user. [Optional]

        Returns:
          A telegram.Message instance representing the message posted.
        """

        url = '%s/sendMessage' % (self.base_url)

        if not self.__auth:
            raise TelegramError({'message': "API must be authenticated."})

        data = {'chat_id': chat_id,
                'text': text}
        if disable_web_page_preview:
            data['disable_web_page_preview'] = disable_web_page_preview
        if reply_to_message_id:
            data['reply_to_message_id'] = reply_to_message_id
        if reply_markup:
            if isinstance(reply_markup, ReplyMarkup):
                data['reply_markup'] = reply_markup.to_json()
            else:
                data['reply_markup'] = reply_markup

        json_data = self._requestUrl(url, 'POST', data=data)
        data = self._parseAndCheckTelegram(json_data.content)

        return Message.de_json(data)
开发者ID:macrojames,项目名称:python-telegram-bot,代码行数:50,代码来源:bot.py


注:本文中的telegram.Message.de_json方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。