Run telegram bot in multiple clusters using pm2 - telegram

I'm currently running a telegram bot using the node-telegram-bot-api.
But now the project is getting bigger and bigger and more users are using my bot.
So I had some difficulties when I had to re-deploy my app while many people are still on access.
I tried to run multiple clusters using pm2 and then use pm2 reload to gracefully restart my app in zero downtime.
But then I got an error from telegram:
error: [polling_error] {"code":"ETELEGRAM","message":"ETELEGRAM: 409 Conflict: terminated by other getUpdates request; make sure that only one bot instance is running"}
I think telegram doesn't provide multiple instances in the same server.
Is there any solutions for this kind of problem?

Even if you could run script twice, users will get answers twice when they sends commands to bot.
you have two options two do:
Upgrade Your resources (RAM/CPU/...)
Handle incoming messages with your main script, make a API and do processes in API backend.

Related

How do I made ngrok server run forever?

I want to have my website online on ngrok 24/7, but it's session will expire after 2 hours. Is there any way to have it run forever, or any alternative software that I should use?
If you sign up for an account on ngrok.com, whether free or paid, you will have tunnels that run with no time limit (aka "forever").
If you don't care about domain address persistence and you use Discord and you want to use it just for testing, sharing it for friends to view you can use this:
https://github.com/winter-b/ngrok-bot
It's a Discord bot which executes shell commands every two hours to restart ngrok tunnel, get the url, and send it to the specified Discord channel.
First create a Discord bot, how to here https://discord.com/developers/docs/intro, get the bot token, put the bot in your Discord server, get the channel id you want to send url's to, put the discord bot token and channel id in settings.json
run in directory
npm install
npm start
it's not perfect, but gets the job done for particular scenarios

Scheduling the javascript script hosted on firebase to run in every 30 minutes

I have written a javascript code, which contains all the necessary firebase database conditioning,on the basis of which I am sending push notifications using fcm. I have hosted the script (index.html & firebase.js) on the firebase.
I want to schedule the script kept on server at every 30 minutes(it should run automatically), so that conditions written on script will be checked in every 30 minutes and push notifications will be sent automatically to the user.
Kinldy, help me to solve this issue.
Thanks.
I have heard of cron task. But I don't know how to implement this with the script.
I want that the push notification should be sent to the user based on the conditions that i have written in the script.
How to schedule this script on server side?
There is no way to schedule running code on Firebase Hosting. In fact: Firebase Hosting doesn't run any of your code. All code in your index.html and JavaScript are sent to any client that connects to your site, and are interpreted there. Which is actually a security risk in your current approach.
Sending FCM messages requires that you specify the FCM server key. As its name implies, this key should only be used in a trusted environment, such as a server you control, your development machine, or Cloud Functions. The latter is probably the best way for you to send these FCM messages, as you can schedule Cloud Functions to run on an interval.

Can a telegram bot running on node.js be hacked

Lets say we have a telegram bot running on node.js using node library: node-telegram-bot-api
Do we need to worry about any security problems, like can someone hack my server and access the source code or data through the API connection?
Don't worry about it, every API connection is through HTTPS, which is regarded as safe.

Connecting Slack, Api.ai & Google Calendar

I know exactly what I want to achieve, but need some help to be able to start.
Flow:
Automatic periodic checking of my gCalendar to see if I just finished a meeting
Sending message to Slack with question "What is to-do list after the meeting?"
User writes a response.
Response get stored in Google Sheet.
My main concern right now are steps 1 and 2: is Api.ai capable of automatic periodic checking of my gCalendar by itself, so when my meeting is over, I get message in Slack and then I can continue normal communication with the Api.ai bot?
The problem I see here is that I expect Api.ai to push a message to Slack after some external trigger instead of waiting trigger from me as a Slack user.
If you haven't done so, you may want to check Bot Users which enable teams to conversationally interact with external services or your custom code by building bot users.
What can bot users do?
The primary way bot users interact with people on a given team is by connecting to the Real Time Messaging API (RTM API for short) and opening up a websocket connection with Slack.
The Events API is an alternative way to receive and respond to events as a bot user contained within a Slack App. Instead of connecting over a websocket, you subscribe to specific events and messages and Slack sends them to your server.
Secondly, you may want to also check the Bot implementation given in this GitHub post or you may try to customize your bot behavior using the following steps:
Clone the repository https://github.com/api-ai/api-ai-slack-bot
Change the code to index.js
In the Docker, use the run command specifying the full path to the directory containing the index.js file:
run command:
docker run -d --name slack_bot \
-e accesstoken="Api.ai client token" \
-e slackkey="Slack bot user key" \
-v /full/path/to/your/src:/usr/app/src \
speaktoit/api-ai-slack-bot
Lastly, for additional information, please also see Slack Integration documentation wherein it gives guidelines on how you can set up Slack Integration in API.AI. Please also see Slack Help Center for ways on how you can connect Google Calendar to Slack.

Does Firebase throttle multiple REST requests from the same server?

We have an application that is running on Heroku and uses Firebase for data. There are some instances where we have to do some logic that require multiple nested Firebase calls (if method 1 succeeds, create object with method 2) and so on. Unfortunately, they seem to be a little more in-depth than what a transaction method on the client side could accomodate.
We are relying on the REST api to do these functions server-side, but have run into issues when stress-testing that they are frequently timing out (especially when issuing a PATCH request).
However, if we run the same test on a different server with the same code and Firebase database, they succeed no problem.
Is there any throttling going on for multiple requests from the same environment?

Resources