delivery-slot-bot icon indicating copy to clipboard operation
delivery-slot-bot copied to clipboard

Telegram issue

Open CharlesButcher opened this issue 4 years ago • 10 comments

Pushover received this one but didn't generate a notification on my phone, and the screenshot was missing. Not sure whether that's related to the stuff below.

Opening https://groceries.asda.com/checkout/book-slot?tab=deliver
SLOTS AVAILABLE!!!
Taking screenshot
ASDA delivery Apr 20 - Apr 23 slots:
[
  { start: 2020-04-21T17:00:00.000Z, end: 2020-04-21T19:00:00.000Z },
  { start: 2020-04-21T18:00:00.000Z, end: 2020-04-21T20:00:00.000Z },
  { start: 2020-04-21T19:00:00.000Z, end: 2020-04-21T21:00:00.000Z },
  { start: 2020-04-21T20:00:00.000Z, end: 2020-04-21T22:00:00.000Z }
]
{"status":1,"request":"012dad58-2e48-4b90-8263-4c2c1ca5ec60"}
/Users/charles/delivery-slot-bot/node_modules/bluebird/js/release/async.js:49
        fn = function () { throw arg; };
                           ^

TypeError: Cannot read property 'channel_post' of undefined
    at /Users/charles/delivery-slot-bot/src/notifications/telegram.js:18:28
    at tryCatcher (/Users/charles/delivery-slot-bot/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/Users/charles/delivery-slot-bot/node_modules/bluebird/js/release/promise.js:547:31)
    at Promise._settlePromise (/Users/charles/delivery-slot-bot/node_modules/bluebird/js/release/promise.js:604:18)
    at Promise._settlePromise0 (/Users/charles/delivery-slot-bot/node_modules/bluebird/js/release/promise.js:649:10)
    at Promise._settlePromises (/Users/charles/delivery-slot-bot/node_modules/bluebird/js/release/promise.js:729:18)
    at _drainQueueStep (/Users/charles/delivery-slot-bot/node_modules/bluebird/js/release/async.js:93:12)
    at _drainQueue (/Users/charles/delivery-slot-bot/node_modules/bluebird/js/release/async.js:86:9)
    at Async._drainQueues (/Users/charles/delivery-slot-bot/node_modules/bluebird/js/release/async.js:102:5)
    at Immediate.Async.drainQueues [as _onImmediate] (/Users/charles/delivery-slot-bot/node_modules/bluebird/js/release/async.js:15:14)
    at processImmediate (internal/timers.js:456:21)
error Command failed with exit code 1.

CharlesButcher avatar Apr 19 '20 16:04 CharlesButcher

looks more like a Telegram notifier issue to me. Did you set up telegram_api_token intending to use it as a notifier?

andytson avatar Apr 19 '20 16:04 andytson

another update also added yarn start send-test which can be used to test all enabled notifiers without needing an available slot on a store

andytson avatar Apr 19 '20 16:04 andytson

Thanks. I did set a Telegram token, and commenting it out makes the error go away. I'd not used Telegram before, so probably my bad. My token has 46 characters – does that look right?

CharlesButcher avatar Apr 19 '20 17:04 CharlesButcher

The telegram notifier doesn't look stable at the moment. It seems to depend on the most recent update event the telegram bot account itself has received to be of a specific format, and it will relay the messages to that channel

If it's latest update event isn't correct, it errors as you see

andytson avatar Apr 19 '20 17:04 andytson

OK, thanks.

I checked their example: https://api.telegram.org/bot/getMe and the result is OK, so my token itself is not the problem.

CharlesButcher avatar Apr 19 '20 17:04 CharlesButcher

Identical error last night. Everything was up to date (including yarn install :-) ), and the Telegram token in config.ini is commented out, so yarn start send-test works fine (Mac-speak and Pushover). Am I doing anything wrong?

Apart from the fact that that the notification was for Tesco this time, there were only two differences: (1) Pushover didn't register anything, and (2) this line (related to Telegram?) was missing:

{"status":1,"request":"012dad58-2e48-4b90-8263-4c2c1ca5ec60"}

CharlesButcher avatar Apr 20 '20 10:04 CharlesButcher

Looks to me that you didn't get an update from the channel for the bot to get the chat id out of.

I'm abusing the telegram api - the api is meant to respond to messages so it needs something can only find the chat id if there are actually past messages in the channel that the bot it associated to. try sending a message in the telegram channel and running - Talking directly to the bot should issue a "/start" message which will be enough

marmitesandwich avatar Apr 20 '20 18:04 marmitesandwich

try sending a message in the telegram channel

Thanks, that worked. But from what @andytson said in #52, that will only persist for 24 hours unless someone makes significant changes to the code (or I just prod the bot once a day)?

Also, I was bothered about last night's failure because at that time there was no Telegram token in the config file. It seems fine now: at least, disabling the token stops Telegram notifications and doesn't break anything else. But could that be simply because my Telegram channel is now alive (in other words will everything stop working tomorrow evening)?

Bottom line: I didn't previously use either Pushover or Telegram, and I only need one system that works. I'm guessing Telegram has some advantages, but it would be nice to be sure it can be disabled without breaking anything.

CharlesButcher avatar Apr 20 '20 19:04 CharlesButcher

there's definitely a simpler solution than my idea for removing the 24 hour issue, in that the first update it finds it keeps a record of the chat ids.

andytson avatar Apr 20 '20 19:04 andytson

for the 24 hour issue, you can just save chat IDs, for instance i save a chat ID in my config.ini: https://github.com/obbardc/delivery-slot-bot/commit/122b9b774bbdce17bfe1bbdfd4dc3b6e3dac6da1

obbardc avatar May 24 '20 08:05 obbardc