Does long-polling work always even if the user switches app? - http

I have an application which sends notification to its subscribers through telegram.
For someone to subscribe, he needs to add his request in my website and after that, to identify his self, he needs to start a conversation with my bot using a secret code generated by the server.
For example, whenever he completes his request he should click a button which leads him out of my website and to telegram's chat (using ), in the background, the website is making long-pool requests to the server to check whether the server received a notification from telegram with this secret code abcd and to get the chat id assosiated with the request so it could store the request with this specific chat id.
The process seems to work just fine for many users, but for minor amount of users it's not working, they are starting a conversation with my bot but not getting any feedback about a success. It seems as whenever they leave the website (or the browser) and follow the path of the link (https://t.me/mybot?start=abcd) straight to telegram app, the long-pool is being stopped.does that happen sometimes when long-polling?

Related

How to send Telegram Message using Google Apps Script?

I have a basic Google App Script which is connected to a Google Sheet and sends a birthday reminder email on the day of someones birthday.
What I would like to do, is send an automated message on Telegram using the same data whilst inside of a group chat.
I don't want the message to come from a Bot account, but rather my own account so that it looks like I have genuinely sent the message myself. :)
Can this be done?
I have searched the web without success. Everything seems to be centered around creating a Bot account.

How to build in app notification service?

I'm learning backend and API development and trying to understand how to implement some features from scratch without using any paid third party service.
I want to understand this concept from design as well as implementation pov. Please share if you have any resources where I can learn how to code the below service.
How to build in app notification service like one of these from scratch ?
Notification when user likes or comments on a post (Instagram, Twitter)
Notification when someone views your profile (Linkedin)
Notication when a channel you are subscribed to uploads a video (Youtube)
These are different from push notifications like
Notification when someone sends you a message (All chat apps)
Live status via notification of your delivery (Food delivery apps)
Push notifications need not be stored permanently in any database but what happens with in app notifications? How to build such service which is scalable too.
One possible solution I could think of is this, for notification on post like
User A has made a post.
User B likes their post.
From likePost API emit an event which will notify User A that User B liked their post, listen for these real time events on client side. This can be done via sockets.
Do not store any notifications in database, just update the notifications in UI on that event emitted by likePost API or listen to real time changes in likes attribute of a User's Post table (is this possible?) and update UI.
In UI just show all such notifications by fetching from likes and comments table.
But I wonder how scalable is this approach.
I searched but couldn't find any good resources regarding this, so please if anyone could explain this or provide link to any blog or videos it will be helpful.
(P.s. I'm an undergrad student and don't have experience in system design and architectures, just started learning about these so just curious)
Thanks.
apps like Facebook, Instagram and linkedIn provides web hook of notifications. Webhooks allow you to receive real-time HTTP notifications for subscribed events. This functionality is only available for applications with an approved use case for webhooks. Webhhook received as a notification when user comment on your post or like your post, a web hook can be used to retrieve the information of post, comment and commentor etc.
I am attaching a reference of LinkedIn web-hook.
https://learn.microsoft.com/en-us/linkedin/shared/api-guide/webhook-validation

How telegram bot knows where to respond?

I am using telethon and I have a question that how telegram knows where to send the request?
I have created a bot on telegram. When the user sends a message to the bot then how telegram knows where to redirect that message. I run my program in my local and also on a server. But in the code, we don't mention anything about the server. But the program is working fine on it also.
Need to understand the flow.
Telethon uses what’s called MTProto to communicate with Telegram servers. It connects just like an actual client would (like TDesktop or Webogram, for instance). Once the connection is made, instead of using a phone number, the authentication is made with the bot token. Then, everything else is standard procedure: Ask Telegram for any new message and Telegram responds with all the messages people sent to the bot or to groups your bot is in (if you have that enabled through BotFather). To cut down on traffic, if there’s an open connection, Telegram may send updates automatically.
That’s the general process flow. For more in-depth explanation of how MTProto works, all the technical information is available on their website. The portion about updates is here: https://core.telegram.org/api/updates
Every handler have an arg, i named it here event , e.g:
#client.on(events.NewMessage)
asynce def handler(event):
This event have all information in it, text of message, message id and etc.

Best way to utilise push notifications when app goes into background

I am a React Native developer currently working on a vehicle tracking app.
We want to develop a feature that allows users to exit the app, but continually be updated in the form of notifications when the vehicle moves (on average every 60 seconds).
I have been tasked with coming up the best way of integrating this. Our app already has push notifications set up with Firebase and we do use this to push out generic messages to the app.
My thinking is as follows:
When a user begins tracking a vehicle, the app should subscribe to a Firebase topic identified as the vehicle's registration. On the server side, each time an update comes in for a vehicle, send out a Firebase notification to that vehicle registration's topic, and then any users tracking it will be updated. When a user returns to the app and presses 'Stop tracking', the app unsubscribes from the topic.
In theory I think this would work. The reason I'm posting is I'm not sure it's the most efficient way. Our server received updates for over 1,000 vehicles every minute.
Any help/ideas would be gratefully received!

How to echo message at telegram /start?

I'd like to set up a authentication through telegram using it's deep linking api.
In order to authenticate, in my app I ask users to click on a link like:
https://telegram.me/myloginbot?start=somesecretkey
If I understand the docs correctly, I should expect the bot to echo back somesecretky to my server.
Now, this step of the docs is unclear to me:
Configure the webhook processor to query Memcached with the parameter that is passed in incoming messages beginning with /start
If I understand correctly, I need to configure myloginbot so that when the user clicks start button on the bot's page, the bot echos back to my server a url containing somesecretkey and some user info. But I don't know how to do so.
In this answer, it is suggested that:
Let the bot retrieve the username by querying the database or key-value storage for unique_code.
But I don't know how can I make the bot query the (presumably remote) database.
So really appreciate your hints.
My understanding to deep linking is this:
You have a database of users. Each user has an ID. Suppose you want your Telegram bot to communicate with user 123. But you don't know his Telegram chat_id (which the bot needs in order to send messages to him). How do you "entice" him to talk to the bot, thus revealing his chat_id? You put a link on a web page.
But the link has to be "personalized". You want each user to press on a slightly different link, in order to distinguish them. One way to do that is to embed user ID in the link. However, user IDs are not something you want to expose, so you generate a (temporary) key associated with each user ID, and embed that key in the link. For example, user 123 has the key abcde. His personalized link will be:
https://telegram.me/myloginbot?start=abcde
Someone clicks on the link, and is led to a conversation with your bot. At the same time (or when he presses the START button), your bot will receive a message:
/start abcde
On receiving that message, the bot sees that abcde is associated with user 123. Telegram chat_id can also be extracted from the message. Now, the bot knows user 123's chat_id, and can send him messages afterwards.
To experiment with deep linking, you need a bot that can handle /start messages, supported by a "datastore" that remembers the key-ID associations. When Telegram docs say "memcache", they just mean something that stores the key-ID associations. For an experiment, it may be as simple as a dictionary, or an associative array. In real life, it may be Memcached (the memory caching software), or a database table.
If you use Python, I recommend taking a look at telepot, a Python framework for Telegram Bot API. It does not do deep linking per se, but it does help you in receiving messages for a bot, and other bot operations in general. I also have an example there demonstrating how to output a personalized link, set up a webhook, and parse the incoming /start command with the key.

Resources