我正在用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链接),我想使用此功能发送。
例如:https://media.wordpress.com/picture1.jpg
为了能够直接发送图片(而不是图片的链接),我如何在我的函数中插入这个lik?
发布于 2020-04-16 10:28:41
使用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')
https://stackoverflow.com/questions/61246523
复制