【问题标题】:Telegram api: send text and photos in one messageTelegram api:在一条消息中发送文本和照片
【发布时间】:2018-03-13 23:53:02
【问题描述】:

我正在尝试编写一个电报机器人,它将墙上的帖子从 VK 组发送到电报频道。 我使用 pyTelegramBotAPI。

        post = u'{!s}'.format(item['text'])
        bot.send_message(CHANNEL_NAME, post)

        PHOTO_URL = str(item['attachments']['photo']['photo_604'])
        img_file = urllib2.urlopen(PHOTO_URL)
        im = StringIO(img_file.read())
        bot.send_photo(CHANNEL_NAME, im)

是否可以在一条消息中发送文字和照片?也许你可以建议我另一个电报机器人库或其他魔法。

【问题讨论】:

    标签: python-2.7 telegram-bot py-telegram-bot-api


    【解决方案1】:

    sendPhoto 方法有一个参数caption。它将出现在图片下方。

    使用 pyTelegramBotAPI 时,只需添加第三个参数作为标题即可。

    bot.send_photo(CHANNEL_NAME, im,"Caption goes here")

    【讨论】:

      猜你喜欢
      • 2018-10-05
      • 2018-11-12
      • 2017-12-05
      • 2020-12-29
      • 2016-02-23
      • 2016-12-05
      • 2015-11-24
      • 2016-07-09
      • 1970-01-01
      相关资源
      最近更新 更多