thp / urlwatch

Watch (parts of) webpages and get notified when something changes via e-mail, on your phone or via other means. Highly configurable.
https://thp.io/2008/urlwatch/
Other
2.81k stars 352 forks source link

--telegram-chat can't handle negative sender_chat id values #622

Open nheinemans opened 3 years ago

nheinemans commented 3 years ago

Adding a bot to a channel (as admin) and mentioning the bot with a /start, this results in a negative sender_chat id value. Urlwatch --telegram-chat can't handle this, resulting in an error message:

urlwatch --telegram-chat --verbose 2021-02-18 12:24:07,135 cli INFO: turning on verbose logging mode 2021-02-18 12:24:07,148 minidb DEBUG: PRAGMA table_info(CacheEntry) 2021-02-18 12:24:07,149 main INFO: Using /root/.urlwatch/urls.yaml as URLs file 2021-02-18 12:24:07,149 main INFO: Using /root/.urlwatch/hooks.py for hooks 2021-02-18 12:24:07,150 main INFO: Using /root/.urlwatch/cache.db as cache database 2021-02-18 12:24:07,157 main INFO: Found 6 jobs 2021-02-18 12:24:07,159 connectionpool DEBUG: Starting new HTTPS connection (1): api.telegram.org:443 2021-02-18 12:24:07,202 connectionpool DEBUG: https://api.telegram.org:443 "GET /bot.../getMe HTTP/1.1" 200 195 2021-02-18 12:24:07,206 connectionpool DEBUG: Starting new HTTPS connection (1): api.telegram.org:443 2021-02-18 12:24:07,246 connectionpool DEBUG: https://api.telegram.org:443 "GET /bot.../getUpdates HTTP/1.1" 200 2392 Traceback (most recent call last): File "/usr/bin/urlwatch", line 33, in sys.exit(load_entry_point('urlwatch==2.22', 'console_scripts', 'urlwatch')()) File "/usr/lib/python3.8/site-packages/urlwatch/cli.py", line 112, in main urlwatch_command.run() File "/usr/lib/python3.8/site-packages/urlwatch/command.py", line 405, in run self.check_telegram_chats() File "/usr/lib/python3.8/site-packages/urlwatch/command.py", line 238, in check_telegram_chats chat = chat_info['message']['chat'] KeyError: 'message'

buzzeddesign commented 3 years ago

Confirmed this is an issue in the reporter as well:

% urlwatch --test-reporter telegram Telegram error: Bad Request: chat not found

buzzeddesign commented 3 years ago

This is resolved in the webchanges project and should work here too! Instead of using the negative chat id, just use the @channelusername like this:

  telegram:
    bot_token: '1234567890:iuasdhoaihofgojsdfoifasofsoiabsfoi'
    chat_id:
      - '0987654321'
      - '@channelusername'

Thanks @mborsetti !

thp commented 2 years ago

Does this only apply to "channels" (i assume group chats) and not "users"?