簡體   English   中英

歡迎消息不起作用,因為 GetUpdates Telegram Bot API 無法在超級組中記錄加入的通知更新

[英]Welcome Message isn't work because GetUpdates Telegram Bot API can't record joined notification update in supergroup

幾天前,我使用https://core.telegram.org/bots/api的 api 制作了一個帶有 python 的電報機器人。 所有代碼都運行良好,直到我意識到 GetUpdates api 沒有記錄我組中新用戶的加入通知

我的計划是根據這些記錄向新用戶發送歡迎信息。 不允許用戶發送消息的組(廣播組),現在我很困惑,我無法獲得與新用戶加入相關的任何單個記錄,因此歡迎消息無法正常工作

這是我的 function 用於 getUpdates api 和歡迎信息

    def get_updates(self, offset=0, timeout=50):
        method = 'getUpdates'
        params = {'timeout': timeout, 'offset': offset}
        resp = requests.get(self.api_url + method, params)
        result_json = resp.json()['result']
        return result_json

    def welcome_msg(self, item):
        chat_id = item["message"]["chat"]["id"]
        user_id = item["message"]["new_chat_member"]["id"]
        if "username" in item["message"]["new_chat_member"]:
            user_name = item["message"]["new_chat_member"].get("username", user_id)
        else:
            user_name = item["message"]["new_chat_member"].get("first_name", user_id)
        welcom_msg = "HI WELCOME TO THIS GROUP"
        to_url3 = 'https://api.telegram.org/bot{}/sendMessage?chat_id={}&text={}&parse_mode=HTML&disable_web_page_preview=True'.format(token, chat_id, welcom_msg)
        resp3 = requests.get(to_url3)

之后歡迎信息應該是這樣的

new_offset = 1
all_updates = get_updates(new_offset)
if len(all_updates) > 0:
   for current_update in all_updates:
     first_update_id = current_update['update_id']
     if old_id < first_update_id:
       old_id = int(current_update['update_id'])
       try:
         if "new_chat_member" in current_update['message']:
           welcome_msg(current_update)
           chat_id = current_update["message"]["chat"]["id"]
           message_id = current_update["message"]["message_id"]
           new_offset = first_update_id + 1
       except:
         pass

組的限制(成員不能發消息)導致getUpdates API 不能工作,歡迎消息沒有出現???

Go 到 botfather,bot 設置並為此 bot 設置隱私模式,它應該可以工作

暫無
暫無

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

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