Slack - behind a “firewall“ - websocket

I've try to create a slackbot. Works fine, but my problems are calls from slack to my rest api. My app is an internal service, so it's not available from the internet. I have seen that outgoing webhooks is possible to set, but I have to forward the request back to the internal service which I don't like very much. As far as I know slack is based on websockets, so is it possible to write a bot which run behind my “firewall“ and get it's commands via websocket?
Greetings
Tonka

You can use services like Localtunnel for receiving webhooks behind a firewall.
We use it with a docker container to develop our slack bot in local env.

Webhooks, slash commands, interactive messages, events etc. are based on HTTP.
Only bots use websockets.
But even this bot websocket session still needs to be initiated with an HTTP call.
Not entirely sure how your firewall is set up, but you may want to make your endpoint public to make things easier.

Related

Push notification from local API in xamarin forms

I am having an API locally hosted in one of the servers (LAN). What I am looking to understand if it is feasible to enable push notification from the server in case of a record entry. Every time a post request is made to the local server, Is it possible to push a notification to a certain mobile device? Please note, I am not considering push notification from web services such as google, Azure, Firebase etc.
It is feasible.
As Sushi said, you can use WebSockets or other Sockets to keep connect between Apps and Server. When client connected to your server, server will record which app is connecting.
By the way, you can custom notification's url between server and app.Use some special characters to distinguish between your various parameters, such as &/[ ]. You are free to set the header and body style of the message. Also, when your message needs to be encrypted, some encryption methods can be used.
Here is a similar discussion about Building an Android notification server can be refer .

Interact with slack bot without a public accessible server

For some security reasons that I can't have a public accessible server to receive data from slack.
So, this is what I'm planning to do:
Inbound message from slack: using RTM API
Outbound message to slack: using RTM API or Web API
Questions:
Any better alternatives?
Any restrictions? (AFAIK, buttons and drop downs can't work)
If Web API reach rate limit, can I use incoming webhook as a backup plan?
RTM only approach
Yes, that would work. With only the RTM API you are limited to:
receiving and responding to messages
Other RTM events.
You can't use any interactive functionality like:
Interactive components (buttons, menus, datepickers)
Dialogs
Rate limit on message posting
Using the webhook as "backup" to circumvent the rate limit is not an option, since the rate limit of posting max 1 message per second applies to all form of message posting.
From the documentation:
In general, apps may post no more than one message per second per
channel, whether a message is posted via chat.postMessage, an incoming
webhook, or one of the many other ways to send messages in to Slack.
Alternatives
You did not give any details about the reasons why your app can't expose an endpoint to the public Internet. But you might want to consider using a VPN tunnel like ngrok.
Yes! Socket Mode
There is a new alternative from slack, Socket Mode, which doesn't require a publicly accessible server.
Note: this is only for private apps.
With Socket Mode you have an API token and your server uses it to communicate with Slack's servers and create a two way socket connection. This means your Slack Bot's code can run on a machine behind a firewall and not require any inbound ports to be opened.
Slack message delivery requires an acknowledgement once you get the message, or else they may retry to deliver it.
Limitations
Socket Mode has two main limitations:
Apps using Socket Mode are not currently allowed in the public Slack App Directory.
Socket Mode is only available for apps using new, granular permissions. If you created your app on or after December of 2019, good news: your app already uses the new permissions. Otherwise, you may have to migrate your classic Slack app to use granular permissions before turning on Socket Mode.

Interactive messages on slack without external service

I'm working on a simple slack bot which is supposed to ask simple questions (yes/no) and based on answers perform some actions. AFAIU I should be using interactive messages for this. The problem is that it's supposed that slack will then call some external URL with the result, but for security reasons, I can't expose any service externally.
I was hoping I can just receive some event (using Events API) from Slack that user choose one of the options and simply read it directly using API. Unfortunately I can't find anything like that.
Is possible to use interactive messages without exposing external service to the world?
Yes. If you build a bot with the Real Time Messaging API you do not need to expose an endpoint to the public Internet.
With the RTM API you open a connection to Slack (which can be from behind a firewall) and maintain that connection. There is no call-back from Slack.
However, the RTM API will only enable you to create a chat bot that can react to events and message posts. The interactive message features like buttons and drop-down menus still require you to provide an endpoint.

How to integrate internal APIs (Not accessible outside office network) to slack slash commands

I am trying to use slash commands to my one of the slack channel. I tried to do a POC using git API and it worked fine.
I first created a slash command from this link :
https://api.slack.com/censored/slash-commands
Commnad: /poc
Request URL: http://jsonplaceholder.typicode.com/posts
This worked fine when I type /opc on slack chat box of my channel. It returns some data.
But when I change the Request URL to an internal API, which is accessible only from the office domain, I get error:
Darn – that slash command didn't work (error message: Failure when
receiving data from the peer). Manage the command at .
I believe, slack is not able to access my internal URL in case. Is that possible to see the slack logs?
Can anyone please help me here.
This can not work, since the request URL needs to be accessible from the public Internet in order to work with Slack.
In general most of Slack's interactive features (Slash commands, Interactive messages, Modals, Events API, ...) require your app to provide a public endpoint that can be called by Slack via HTTP.
In order to access internal APIs with Slack you will need some kind of gateway or tunnel through the firewall of your company that exposes the request URL to Slack. There are many ways how to do that and the solution needs to be designed according to the security policy of your company.
Here are a couple of suggestions:
VPN tunnel
One approach would be to run your script for the slash command on an internal webserver (one that has access to the internal API) use a VPN tunnel to expose that web server to the Internet, e.g. with a tool like ngrok.
DMZ
Another approach would be to run your app in the DMZ of your companies network and configure the firewall on both sides to allow access to Slack form the public Internet and your app to you your internal network.
Bridge
Another approach is to host and run that part of your app that interacts with Slack on the public Internet and the part that interacts with your internal network on your internal company network. Then add a secure connection that allows the public part to communicate with the part running on the internal company network.
If opening a connection into the internal network is not an option, there is another way that can allow communication with internal services by inverting the communication direction with a queue.
To do this, you need to deploy a public endpoint that accepts the requests from Slack and puts them onto a queue (e. g. AWS Lambda + SQS, Flask + RabbitMQ) and then poll the queue from the internal network. The polling needs to happen fairly often (at least once a second) to ensure the communication is quick enough for the users not to notice the lag too much. By doing this you can avoid exposing any endpoint of the internal network.
The drawbacks of this approach are more infrastructure complexity and slower response times, but it can be a good alternative in some corporate environments.

How to setup a SMS Gateway on Windows 7 and test with .NET

My company is working for a Telco who will allow us to send/receive sms using their gateway eventually but for now I need a sms gateway setup on my Win7 box that I can used to test and build an applicaton that sends and optionally receive sms messages.
I have had a look at Kannel but I cant seem to find a Win7 version or dont know how to compile and setup one on Win7.
If someone has any experience in this then please help me. Thanks
If you will be connecting to the telco it will probably be to their SMSC directly via SMPP or similar protocols, which means you will need to setup something to talk to that. Kannel is an excellent open source implementation of an SMS Gateway, and probably your best bet at this. It will take care of talking with the telco's SMSC, and will provide you with a simple HTTP based interface to submit messages to from your application.
In that case, you are better off trying to set it up sooner rather than later, because quite a bit is involved in Kannel's configuration. It requires linux based systems to run and there is no windows port.
However, in order to get started developing your application, you can look into a fake SMS Gateway that will accept the same HTTP interface as Kannel, and return back made up replies. A quick and dirty way would be to write a simple web page in any language you wish, that will accept a few parameters over a web request and print out "55124" for the new message id, or similar. Then your application can do a simple HTTP call to it to simulate sending an sms:
http://smsgateway.local/simulator.php?to=12345678&from=12345&body=hello+there
If you want something more realistic look at this list of software. There are some libraries for sending sms via mobile phone connected serially, and SMPPSim which looks like it could work for you for this.

Resources