How to check, that telegram bot is alive automatically? - telegram-bot

I wrote a telegram bot, but it go frizes sometimes, and don't answer to the messages.
How to check the state of bot automaticaly (for exmaple from another server).
I think, that I need something like heartbeat check:
Send a message from non-webhook server.
Catch telegram response
If response not comes in reasonable time, bot is die.
But, I need telegram client on linux server to do it.
Do you have any ideas, how to check telegram bot state?

You need to find out why the bot freezes, the health check is not the answer to your problem. However If you really want to implement some kind of automated health check, you need to use Telegram CLI to send requests to your own bot in fixed intervals and check for incoming messages from that CLI user.
If you are experiencing problem with Telegram's webhook, try long pulling the updates using the getUpdates method. I know a few high traffic bots that use that method, Webhooks have a max amount of concurrent requests so if you just delay them for a few milliseconds, it will start accumulating delay.

Related

Telegram Bot API getUpdates() does not deliver updates after user have not interacted with the bot for a few days

As a telegram bot api developer, I noticed a weird behaviour of the getUpdates() api method:
If the user have not interacted with the bot for a few days, then the next time it sends a message to the bot, the message does not get delivered via the long-poll.
The workaround is to "cleanup the chat" - then all of a sudden the messages get delivered again. But this workaround is ugly.
What can be the cause of this issue, and is there any "lighter" workaround that will not touch the chat history?

How can I prevent duplicated output from incoming webhooks in Slack?

We have set up HealthChecks in Cloudflare that use Slack's webhooks for informing our teams in a Slack workspaces about changes of some server's health conditions.
Initially, this went fine, but then, time after time, the different Cloudflare notifications started to create double output in our respective workspaces.
Cloudflare's dev were able to proof that they only call the webhook api once per message, but nevertheless, they appear immediately twice, as if the same message would be duplicated and then sent to the channel.
And so the fact that deleting the notification on the Cloudflare- side and creating a new one did not change the phenomenon came to no surprise.
Deleting the webhook for the Slack workspace and creating a new one and assinging it to the notifications in Cloudflare helps, though. But only for a limited undetermined time.
Does anyone have experience with this phenomenon and can tell me why this is and/or how I can prevent the Cloudflare notifications from appearing twice each in our Slack workspaces?

Selenium Webhook equivalent / listen to new data from telegram without bot

I have a web scraping project that requires the scraper to wait for when there is new data. I thought about reverse engineering the websocket but that might take some time.
if you know how to work with the telegram websockets to get data without a bot I'd appreciate it
So what I will need to do is get the web scraper to wait for new messages on a telegram chat and only execute action when a new message is detected, it might need work with javascript event listeners or something but I wanted to ask for the most efficient solution for the given problem.
thanks

How could the app send a message to the phone when certain mission fulfilled?

I can use FCM console to send messages to all users or certain users at a certain time.
Now I want the app send a message to specified users when their in-game energy is full. How to realize it with FCM? And can I know the messages' sends, opens, conversions?
Sending a message to a user can only be done from a trusted environment, such as the Firebase console, or a place where you can trust that the code running is yours (such as your development machine, a server that you control, or something like Cloud Functions/Cloud Run).
For examples of how to send a message by calling FCM's API, see the documentation on building send requests, and this sample use-case of notifying the user when something interesting happens using Cloud Functions.

Telegram bot authentification

A web service that contains all the methods for processing data is stored by Azure. In this case, only my telegram can process this data. Other applications are not allowed. But there is a possibility of expanding the service.
How do I know that the service is used by my telegram bot?
How to authenticate the application.
Well, I tried to use OAuth2.0, but i think it is not correct, because user is already authentificated with telegram, when he use telegram bot. My idea was to send a link to google auththentification in the beginning of bot job. By th way, ok, we know user`s data. May be I can check: Id, login etc. But some hacker can substitute this id
How can I make sure that Webhook requests are coming from Telegram? If
you‘d like to make sure that the Webhook request comes from Telegram,
we recommend using a secret path in the URL you give us, e.g.
www.example.com/your_token. Since nobody else knows your bot’s token,
you can be pretty sure it's us.
Telegram Bot FAQ