使用 HTML 模式使用 Telegram Messenger API 发送在线照片
Send online photo with Telegram Messenger API with HTML mode
我正在使用 Python 为 Telegram Messenger 创建一个机器人。
我正在使用以下功能:
def telegram_bot_sendtexHTML(bot_message):
bot_token = 'token'
bot_chatID = 'id'
send_text = 'https://api.telegram.org/bot' + bot_token + '/sendMessage?chat_id=' + bot_chatID + '&parse_mode=HTML&text=' + bot_message
response = requests.get(send_text)
return response.json()
我有一张在线图片列表(带有 URL link)我想使用此功能发送。
例如:https://media.wordpress.com/picture1.jpg
如何在我的函数中插入这个 lik 以便能够直接发送图片(而不是图片的 link)?
使用 sendPhoto
而不是 sendMessage
方法。
documentation.
中很好地描述了所需的参数
我已将您的 telegram_bot_sendtexHTML
函数更改为 telegram_bot_sendImage
;
def telegram_bot_sendImage(caption, url):
bot_token = ''
bot_chatID = ''
send_text = 'https://api.telegram.org/bot' + bot_token + '/sendPhoto?chat_id=' + bot_chatID + '&parse_mode=HTML&caption=' + caption + '&photo=' + url
response = requests.get(send_text)
return response.json()
telegram_bot_sendImage('Cool image!', 'http://placehold.it/200x200')
我正在使用 Python 为 Telegram Messenger 创建一个机器人。
我正在使用以下功能:
def telegram_bot_sendtexHTML(bot_message):
bot_token = 'token'
bot_chatID = 'id'
send_text = 'https://api.telegram.org/bot' + bot_token + '/sendMessage?chat_id=' + bot_chatID + '&parse_mode=HTML&text=' + bot_message
response = requests.get(send_text)
return response.json()
我有一张在线图片列表(带有 URL link)我想使用此功能发送。
例如:https://media.wordpress.com/picture1.jpg
如何在我的函数中插入这个 lik 以便能够直接发送图片(而不是图片的 link)?
使用 sendPhoto
而不是 sendMessage
方法。
documentation.
我已将您的 telegram_bot_sendtexHTML
函数更改为 telegram_bot_sendImage
;
def telegram_bot_sendImage(caption, url):
bot_token = ''
bot_chatID = ''
send_text = 'https://api.telegram.org/bot' + bot_token + '/sendPhoto?chat_id=' + bot_chatID + '&parse_mode=HTML&caption=' + caption + '&photo=' + url
response = requests.get(send_text)
return response.json()
telegram_bot_sendImage('Cool image!', 'http://placehold.it/200x200')