NodeRed: How to get reply from Slack app interactive message - node.js

I'm trying to make it so that NodeRed uses a webhook to send an interactive message to a slack app to ask permission to activate something. I can POST to the webhook without any issues from my custom node, but how do I get the reply?
Do I need to use the "http in" node to create an endpoint Slack can use? Is there a way to handle it from the same node that POSTs the message?
Also, I'm running NodeRed locally. Can I use ngrok so that Slack can access the http endpoint (in case I need to use that)?

You can define your own http endpoints that are private to your custom node, this is how nodes that need to do oAuth handle the callback. Also nodes like the serial port node do this to supply information to the config dialog.
Make sure to give the endpoint a unique route so it's unlikely to clash with any other nodes.
You can look at the source for the serial port node here
How you ensure that Node-RED is safely made accessible from the internet should be a separate question.

1) Yes, ngrok works nicely for exposing your local webserver securely to the Internet and Slack. I use it every day for my Slack app development. Keep in mind that if your app can't be reached from the Internet, then also Slack can not reach it.
2) Interactive Messages only work with Slack apps. One reason being that you need to provide the route to your app, so that Slack knows where to send the requests when someone uses your interactive messages (e.g. clicks on a button). But you can use interactive messages with webhooks, as long as both are setup within the same Slack app.
3) Don't believe the "http-in node" approach will work. As said, you need to configure the route to your app for receiving messages from Slack in your Slack appp.

Related

Communicating with a remote server via microsoft Teams

Scenario:
I have a remote server which is monitored (via DataDog) and sends out a warning when some anomaly is detected. This warning can be fetched via a webhook. Now I want to connect that webhook (https://docs.datadoghq.com/integrations/webhooks/) with MS Teams (probably via Bot), to receive a warning. Then I want to send a command back to the remote server to resolve the warning.
Technology:
MS Teams, Python flask/Django, remote server
Expected Results:
I can receive a warning from my remote server to MS Teams via a bot. Then send a command back to the remote server. My initial plan is doing this using Python Flask/Django but not tied to a specific language.
Environment:
Remote server is a LINUX based system. we have a internal network that is used within our company, so might need to resolve a firewall problem potentially (idk whole lot about it tho).
Things I have tried:
I just want to see if this is possible or not, so i havent coded up any. But I found some information relevant to our problem:
https://docs.datadoghq.com/integrations/webhooks/
https://learn.microsoft.com/en-us/microsoftteams/platform/bots/how-to/create-a-bot-for-teams
https://learn.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/what-are-webhooks-and-connectors
One last note, I am not also tied down to Teams bot. Our company also uses Azure Devops, so that is another resource I can use to realize the solution.
Btw, this question was posted on here but was told to post on MSDN, but I couldn't find an appropriate forum. Hence, I am posting on stack overflow instead
As you have limited requirements, you could achieve this without a bot.
MS Teams has income and outgoing webhooks. You could create a Incoming webhook inside a Teams channel. It provides an URL which you could use inside the monitoring remote server and POST the message in JSON format to the webhook url. It will be posted in teams channel like below
For sending message back to the server you need to configure the Outgoing webhook in the channel.

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”

Is it possible to receive webhook events in web extensions?

We need to get webhook events from a domain in the web extensions itself. That domain is not under our control.
We get the web extension's URL using browser.identity.getRedirectURL(). We have registered this as the webhook POST callback URL in other domain.
Is it possible to receive the webhook events whenever the other domain POSTs the data in callback URL? Would it be sufficient to intercept HTTP headers in order to get the data or would we need to have Node modules/servers inside the web extension?
No, not like you described. This is a pretty deep misunderstanding how webhooks and/or browser.identity work.
Your webextension is running on a client machine; it's not a webserver listening for connections (an extension can't do that at all).
So whenever some other machine that emits a webhook event tries to connect to the endpoint provided, whatever it connects to is not your extension.
You make an allusion to browser.identity.getRedirectURL() and seem to think that this is a real address that is assigned to your webextension and others can POST to it (and your extension be somehow informed about it).
This is not the case: instead, it's a "virtual" URL that the browser will treat specially if you (the browser) navigates to it. That request never actually leaves your machine to some server. No other client can connect to it (except for other browsers with the same extension - but again it will only ever reach them).
A solution for receiving webhooks would be to have an actual webserver somewhere that can receive them, plus some sort of push mechanism to inform your extension of the event:
A persistent WebSocket connection to your "receiver" server.
GCM push messaging initiated by your "receiver" server. Not for Firefox

What are webhooks in the BugHerd API and how can they be created?

I'm currently working with the BugHerd API.
Please suggest how to create webhooks. I have google understand they are new functionality in apis and they used for two way communication.
They're a way of asking a remote server to make a request of your own server when events happen on the remote server. They allow you to receive real-time events without constantly polling the server. They're basically callbacks that happen between two severs over HTTP.
As for creating them, the API is pretty clear. Make a post request to POST /api_v2/webhooks.json and include JSON in the following format:
{
"project_id":1,
"target_url":"https://app.example.com/api/bugherd_sync/project/1/task_create",
"event":"task_create"
}
You're telling it which event to hook into, and which URL their server should contact when the event occurs.

How Nest thermostat communicates

I want to build a Raspberry Pi (RPi) based device similar to the Nest Thermostat, except that I want to control light switches. I know I could easily code up a Node.js script on the RPi and then just hook it up to my local router and control it with a PC hooked up to the same router.
But, I want to make it more like a Nest. I want to be able to control 20 (or more) RPis across different subnets through a cloud provider like Heroku.
The Nest thermostat does not require the user to open a port on their router so that the Nest server can communicate with it.
How is Nest able to control customer's thermostats over the web without enabling port forwarding in the customer's router?
Blog post Nest Thermostat API using Node JS and Nest API Update discusses the API
between the thermostat and the nest lab servers. In particular:
The API uses mostly JSON formatted data POSTed to their web servers.
So there is your answer. By periodically POSTing data to the nest web servers using HTTPS, Nest is able to avoid having the user open any ports on their router.
For what it's worth, the unofficial API (in node.js!) from the blog post is available on github: Unofficial Nest API on Node.
I think the thermostat periodically posts a request with the thermostat serial number to nest. It may have timeouts in the http headers set to infinity or more likely, the nest server simply closes the connection after a minute or so if no command for that device has come in. Whenever nest closes the connection the thermostat opens a new one. When a command request comes in with serial number, its a quick lookup to find the thread currently connected to that thermostat. The command is sent in the payload of the current thermostat request, which is executed, the connection is closed, and the thermostat opens a new request to nest .
Take a look at eventSource in the HTML 5 standard. It does everything that is required.

Resources