Node-Red Telegram chat through two bots - telegram-bot

I want to design a chat system through Node-Red that two Telegram bots which in one side there is an operator who has the other side's Telegram user ID. I designed it so it asks for user ID, then asks for message, and sends it to the other bot, and the other person only can write to the operator, but it does not work.
Well, I do not know how to transfer one variable from one node to the other without making it global.
Can you help me?

Related

How to implement Telegram bot as a widget on your website?

I'm trying to create some sort of live chat widget, but with a Telegram bot instead of a real person on the other side. I don't know if it is possible, but ideally, there is a chat window that can be implemented on a website, and establishes a new connection with a telegram bot once you click on it. The end-user should NOT have a Telegram account. I already tried to implement Intergram but it's not exactly what I'm looking for, as it merely forwards the message to a human using webhooks, and the bot is only used as a message broker. I have heard that some customization is possible using tdlib but I'm not sure if it can help me achieve the desired result.
How should I start implementing a chat window with my bot on a website?

How to chat and call automatically in MS Teams?

I'm working on a solution to build a system that automatically alerts users on Microsoft Teams. The order of execution will be:
Automatically scan alarm logs
Sort and send MS Teams messages to personnel for corresponding processing
If the processing staff does not receive the message, make a call on MS Teams to read the pre-recorded voice record.
I used python to automatically get the warning list, to send this alert list to the handler, I have tried MS Teams REST API but it only supports sending messages to Channel. How do I automatically chat and voice calls to an MS Teams user? Can chatbot help me with this problem? I see there are many types of bots that can be added to the conversation:
I think a chatbot is definitely the best way to deal with this. Essentially, you're wanting the bot to message a user on demand, which is something called "Proactive Messaging". You can read more here and here. There are a few things you need to know about this, but in a nutshell you need a way to specifically identify the user for sending the message, which you can get when the user first installs your bot (mostly you need "ServiceUrl" and "ConversationId").
With regards to knowing if the user has read the message, you might want to send an "adaptive card" with a button for the user to acknowledge that they've read the message, and if you don't get a callback within some time frame, start the voice call.

Telegram Bots: Can I now start a chat or not?

https://core.telegram.org/bots clearly says:
Bots can't initiate conversations with users. A user must either add them to a group or send them a message first.
But if I visit https://telegram.org/blog/login it says
Telegram bots are a powerful communication tool, but until today they couldn't start a conversation. Even if you wanted them to reach out to you, you had to chat them up first.
With the new login widget, moving from interacting with a website to a conversation on Telegram becomes completely frictionless.
So it is somehow possible to start a conversation via the login widget. But how do I do it?
I get a user id. Is there an api endpoint to initiate a chat with the user?
The only way to begin conversing with a Telegram bot is to start the conversation with them yourself. There's no way for the bot to start a conversation with a user themselves.
As you said, telegram clearly says there is no way for bot to start a conversation, the only thing bots can do is sending messages to an old conversation (I mean a user have to start the conversation).

Is there any way to transfer Telegram file IDs between different bots?

Many different media types on Telegram have a file_id and file_unique_id property, such as Stickers, Audio, and Document.
The file_id property is unique to each Telegram bot, so one Telegram bot will not report the same file_id as another Telegram bot will, even if it's the same piece of media.
I want to have two Telegram bots communicate with each other, but they are currently unable to do so because the file_id property is meaningless when one bot tries to talk to the other.
The file_unique_id property is consistent between the bots, but it does not seem like you can do much of anything with that identifier.
Is there any way to pass a reference to a file stored on Telegram's servers from one bot to another, without having to re-upload the file on both bots?
Bot can't interact with each other. But there's a workaround,
we can use channels as a medium (with only BotAPI)
Steps,
Add two bots as admin in channel
Broadcast the messages from Bot A to channel
Now, the Bot B will get these as channel posts and your new fileid
for the same file which will be unique for Bot B (obviously)
You have officially transferred all fileid to Bot B
There aren't any official methods to share fileIds between bots. In fact, you can't even get 2 bots talk to each other, also you won't get bot updates in groups. So bot to bot communication is not possible at all at this moment.
But what you can do is to use Mtproto api and sign-in to telegram as a normal user (with phone number). And follow these steps using the logged in account:
Start both of your bots.
Forward messages you receive from bot 1 to bot 2.
This way you'll be able to access any files in bot 1 in bot 2.
You can use Telethon to write a script that does the job for you, listening to updates coming from bot 1 & forwarding them to bot 2.
Also using normal bot api you should forward received messages to your logged-in account.
The only way is to use a shared channel. Both bots have admin access. However, you may encounter error 429 while transferring the file.
The solution is to send the files to the channel at longer intervals.

How to manage in RASA an unique user_id for many channels in parallel?

I have to design an e-learning tutorbot that has multiple possible channels living in parallel:
A live chat (to support learner with FAQ when browsing the e-learning application website)
A IM chat as Telegram (for asyncronous notifications)
An email (for anything else)
...
Take a part the connectors gateway communication logics.
My problem/question is mainly about how to manage user identification.
I want that a user is identified with an unique identifier (call it conversation_id) regardless of channel.
In the mentioned scenario user has one different ID for each channel:
An account_id on the website (e.g. solyarisoftware)
A chat_id on Telegram (e.g. 1234567890)
An email_address (e.g. giorgio.robino#blabla.com)
So, how to let RASA chatbot accept requests coming from the same user (but from different channels)? In other words, how can I map multiple channel IDs into a RASA unique ID, say the conversation_id ?
At the end of the day I need to generate a lookup table that map a UUID with all channel ids. Right?
But is not clear to me what's a good (simple) user experience. At first glance seems to me that that I need a sort of login/registration flow: each time user submit a request on channel X, only for the first time, the user must identify himself somewhere (with his email/account_id?). So by example trough Telegram, when the Telegram connector server receive a /start command, the bot must ask the user email(or account_id), to be able to associate 1-to-1 the TG chat_id with that email. Not perfect in terms of security, I admit.
Any experience/idea/suggestion?
Thanks/giorgio
I don't have an hands-on experience on this but it is something I have been thinking myself for a while.
Indeed the 'merge' of the different accounts (across channels) is something that we need to maintain ourselves, making sure each channel user ID is eventually mapped to a universal user ID (lookup table makes sense to me).
Since you have a website, an email address and multiple channels I would say the assumption is that users first registered on the web site. Each user has a unique email address and obtains an account secured by username/password, as well as a unique secret token.
When chatting on browser (ie Rasa WebChat) you can initialise the plugin with custom parameters (ie userId=1 or token=X), in this case the chat session is assigned to the given user id.
When using Telegram (or other messenger application) I would (at the very first access) ask the user if he/she has already registered. If yes then I would ask the token: this can be used to perform the map and link this Telegram user to the universal user Id. Same approach for other channels.
Depending on your needs you might need to deal with anonymous access (users don't provide the token) or maybe you want to provide a different token for each channel (more secure, but requires more work and an easy way to explain this to users).
Finally something to look at (I haven't tried myself) is the possibility to provide in the web site the option to open Telegram (or others) passing an extra parameter, which would allow you to perform the mapping. I don't know if this is possible, but it would simplify this process for your end users. Or the other way around: the users in Telegram could be provided with a link which opens the website, where they can login and be recognised.