簡體   English   中英

使用 Telegram Messenger API 使用 HTML 模式發送在線照片

[英]Send online photo with Telegram Messenger API with HTML mode

我正在使用 Python 為 Telegram Messenger 創建一個機器人。

我正在使用以下 function:

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 鏈接)我想使用這個 function 發送。

例如: https://media.wordpress.com/picture1.jpg

我怎樣才能在我的 function 中插入這個贊,以便能夠直接發送圖片(而不是圖片的鏈接)?

使用sendPhoto而不是sendMessage方法。 所需的參數在文檔中有很好的描述。

我已將您的telegram_bot_sendtexHTML function 更改為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')

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM