A query regarding running automations #188
Replies: 5 comments 1 reply
-
you can either schedule a message (this is a telegram feature) or you'll need to have a backend app running 24/7. |
Beta Was this translation helpful? Give feedback.
-
I think I would need to go for the second option as forwarding of messages needs to be instant as soon as the user receives a message, it should get forwarded to destination chats. I've done the logic for this already anyways but I had it running on the frontend and now need to move it to the backend. So the code I have written, that code needs a reference to the user's firebase UID (all the automation data is in Firestore) and also it needs the telegram client instance. I know I can't create a telegram client instance for every automation, that would be silly. So to run the code on the backend I need 2 things:
I've already got all this information on my backend now. Now this is where I am stuck because the code I showed above has all the logic needed. The only issue is I don't know how and where exactly I need to run that code. Any ideas you have would be much appreciated, thanks. |
Beta Was this translation helpful? Give feedback.
-
You would run it as any other normal JS code. const client = new TelegramClient(...)
await client.connect()
await client.forwardMessages(...)
await client.disconnect() Make sure to disconnect after you finish to clean up everything. Also having a long running process is usually better for these kind of things but I don't think firebase has that. |
Beta Was this translation helpful? Give feedback.
-
Since the library is using promises you don't need to care about long running jobs. Node does all of that on itself. just run your code normally and everything will be sorted out . |
Beta Was this translation helpful? Give feedback.
-
Oh ok. I will give it a go and try implement it. Thanks again for all the help. |
Beta Was this translation helpful? Give feedback.
-
I just want to say, thank you to everyone for making this library and contributing to it.
I have a question regarding creating automations of some sort. So basically on my frontend, user's can choose to pick which chats they want to forward from. So I'm trying to create automations around that. The only issue is I need to run the telegram code which runs the forwarding of messages code on the backend.
The reason for this is that obviously if the user closes my frontend app, then the process is no longer running. So any event listeners I had running on the webapp will be removed since the webapp is now closed.
An example of the code I was running on the frontend is shown below:
How would I go about running this on my backend API (I'm using NestJS)? Also, all the data for these automations is saved to Firebase's Firestore. I just need a solution to running this kind of code for 100s of automations that will be created by users on the platform.
Also I do know that each user will need to authorise with the telegram client and pass their session in order for my server to run the telegram code on behalf of their account. I've thought maybe this automation stuff might not be possible using Telegram's API due to this telegram client limitation, but if you guys know how to do it, please let me know.
Thanks for all the help and guidance.
Beta Was this translation helpful? Give feedback.
All reactions