api.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:py_mbot 作者: evgfilim1 项目源码 文件源码
def send_text_message(self, chat, text, markdown=False, html=False, reply_to=None,
                          force_reply_to=False, **kwargs):
        """Sends message

        Notes:
            For now, this method supports only sending message with markdown or HTML parsing

        Args:
            chat(int|str): chat ID or '@channel_name'
            text(str): text to send
            markdown(Optional[bool]): parse text as markdown
            html(Optional[bool]): parse text as html
            reply_to(Optional[int]): ID of message to reply to
            force_reply_to(Optional[bool]): Replies to message even in private chats

        Returns:
            int|bool: message_id if message was sent, ``False`` otherwise

        Raises:
            ValueError: if ``markdown`` and ``html`` are both ``True``

        """
        if markdown and html:
            raise ValueError('`markdown` and `html` are self-exclusive')

        if markdown:
            parse_mode = ParseMode.MARKDOWN
        elif html:
            parse_mode = ParseMode.HTML
        else:
            parse_mode = None

        if reply_to and self.is_private_chat(chat) and not force_reply_to:
            reply_to = None

        try:
            msg = self._bot.send_message(chat, text, parse_mode=parse_mode,
                                         reply_to_message_id=reply_to, **kwargs)
        except TelegramError as e:
            logger.exception('Exception was raised while sending message', exc_info=e)
            return False
        return msg.message_id
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号