paulmaunders / delivery-slot-bot

A puppeteer based bot to monitor supermarket online delivery slots.
MIT License
54 stars 27 forks source link

Telegram issue #48

Open CharlesButcher opened 4 years ago

CharlesButcher commented 4 years ago

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.
andytson commented 4 years ago

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

andytson commented 4 years ago

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

CharlesButcher commented 4 years ago

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?

andytson commented 4 years ago

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

CharlesButcher commented 4 years ago

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 commented 4 years ago

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"}
marmitesandwich commented 4 years ago

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

CharlesButcher commented 4 years ago

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.

andytson commented 4 years ago

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.

obbardc commented 4 years ago

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