slackbot replies with duplicate message, when its running on HA - node.js

I have developed a slack bot (which is part of my an existing node.js app) which works fine on my dev environment.
But as soon as I deployed this on my staging instance of the app, it started responding to me with duplicate message.
My staging server (example.com) consists of 2 machines for HA, and code gets deployed on both the machine. So I dobut, since bot is running on both the machine, its giving me duplicate replies.
Can anyone please let me know how to ask bot to reply from either of the server. Or let the bot reply only once.
I hope my question is clear, let me know if you need any mroe info.

Related

Unable to run the angular application. Getting error No such file exists robots933456.txt

I am running the angular application in Microsoft Teams and deploying it on Azure.
But it's not running up as it is looking for the robots933456.txt route.
It wasn’t the case before today.
Please guide me on how to proceed further.
On running the app the logs shows:
The error was natively on my side nothing to do with the above but pretty much seen and raised by people so thought of sharing below:
After doing some research figured out I can safely ignore this message. /robots933456.txt is a dummy URL
the path that App Service uses to check if the container is capable of serving
requests. A 404 response simply indicates that the path doesn't exist, but
it lets App Service know that the container is healthy and ready to respond
to requests.
https://github.com/MicrosoftDocs/azure-docs/issues/32472

Setup secondary redundant failover Node.JS server

Introduction
So I made a discord bot and hosted it on Heroku server. The bot is basic, it just listens to new messages and responds to them.
I am using a free tier of heroku and discovered that there are so called "free dyno hours". When it is end of the month, all the free hours are consumed and my bot will go offline until next month.
I own a Raspberry pi and so I thought it would be a good idea to host it there as well in case Heroku goes offline.
What I want to achieve
Host discord bot on hosting platform(Heroku).
use my Raspberry pi as a failover server.
Ensure that only one instance of the bot is running at a time.
If both servers are online Heroku(chosen as the main server) has priority.
If the application on Heroku somehow crashes or goes offline the bot on my Raspberry gets activated.
And vice versa.
How would that work if I had 3 and more servers?
How would I approach this if I had the bot connected to database?
This is just an example I would appreciate if more general solution would be provided.
NginX(load balancer)
When searching for help, I came across load balancers and NginX.
If I am right, it basically functions like a gateway, all requests go to the server NginX is hosted on and then they get redirected to one of many servers(depending on how loaded they are etc.).
I have few problems with this:
my bot doesn't receive any requests, it just listens to the discord api.
if the server with Nginx fails it all falls apart?
My solution 1
My first approach was to let the bot running on both Heroku and Raspberry at the same time.
It guarantees that the bot runs on at least one server if the other one fails.
But it is not ideal as the bot responds 2 times when both servers are up.
My solution 2
Heroku:
I added a simple Rest api endpoint with express.js to the bot app.
This way I can check if the bot on Heroku is running.
Raspberry pi:
I wrapped the bot app with this Node program that basically functions like a switch.
Link to a git repo: https://github.com/Matyanson/secondary-node-server.git
Every 3 minutes the program calls the endpoint and then by looking at the status code it checks whether the app is down.
Then it either starts the app or shuts down the app on raspberry(using pm2).
This kinda works but I am sure there is a better solution!
There is also a problem with Heroku(you can skip this):
Heroku uses Dynos(containers) to run the apps. There are different configurations of dynos including 'Web' and 'Worker'.
Worker is used for background job and never is never put to sleep.
Web dyno is the only dyno to receive HTTP traffic. It is put to sleep after 30min of receiving no web traffic.
I can switch on/off either of these.
both: there are 2 instances of my bot.
Worker: Can't connect to the endpoint.
Web: have to 'ping' the api at least every 30min or the bot sleeps.
Why am I asking?
Not because I need to solve this exact problem but because I want to learn a good way of doing this to use it in the future projects.
I also think this would be a good way to not 100% rely on external Hosting providers.

Not receiving when posting a message through bot using an outgoing webhook on teams

I'm running a node.js server as my local using the method specified here. Although, I'm unable to receive anything at the ngrok server itself when I #mention my bot and send the message. I've followed all the steps as provided in the link diligently. Is there any way I could debug this?

How to integrate a database to api.ai chat-bot using a webhook

I'm developing a chat-bot using api.ai for NLP and i'm stucked where i need to query some data from a database. And also i need to do some processing of those data. I'm not much clear how can I do this using the webhook. Any thoughts and tips would be really appreciated.
You might want to check out API.AI's getting started guide, the last part of which involves the basics of adding fulfillment to your agent which pulls from this getting started sample
We use Cloud Functions for Firebase in the sample but you can't call non-Google APIs or URLs without setting up billing. You can also use any other hosting providers (Google's AppEngine, Compute Engine, Amazon's Lambda, EC2, Heroku, Azure, etc.) for fulfilling API.AI agents, as long as you have a server that can respond to a HTTPS request, it'll work with API.AI's webhook fulfillment. To get started you can even use your local machine and tools like ngrok to tunnel the connection from a HTTPS URL to your local development machine: https://ngrok.com/. If your just starting out I'd recommend doing whatever your most comfortable with.
Am currently using Node-RED to process the data received through the webhook. The webhook receives the data in JSON and if you’ve setup your intents and entities correctly, you’ll get data that you can act on.
This can be achieved as a stand-alone nodeJS app that you host somewhere, like Heroku or OpenShift. But important point is that you need a server running a program somewhere to process the data that api.ai sends.
Am using firebase as my database and is integrated into my Node-RED setup and now I can do sophisticated queries like “how much did I walk last Wednesday”

Pusher keeps giving 401 error on production

I have Pusher integrated into my web app. It's a Java based app running on Windows server 2008. The Pusher Server library is the one available on their website.
I've been using Pusher on my development machine and staging machine with no problem. I only use public channels, and only 2 public channels (an admin channel and an "other user" channel. Everything works as expected when my application is deployed to dev or staging servers.
Errors start occurring when I push to production though. I continually get 401 errors, like Pusher isn't authenticating my credentials. This is despite the fact that the credentials between dev/staging/prod are exactly the same, and the code is unchanged.
Am I missing some setting? Firewall setting? Is Pusher caching some information I don't know about? I'm at a loss about where the problem could lie.
To prove the error is specifically on the production server only, I can log in as an "other user" against the production machine (loading the Pusher client code), then fire an event as an admin on my development machine (loading the Pusher server code) and it works. When I fire the same admin event from my production machine, that's when the 401 errors occur.
Server returned HTTP response code: 401 for URL: http://api.pusherapp.com/apps/....
Found this after digging around a while. My system time was off by an hour on the production server, which gave the error from Pusher, and explains why it worked fine on dev and staging but failed on production with exactly the same code.

Resources