I am trying to connect to slack RTM (Real Time Messaging) api and update the database with the messages coming from the slack channel. How should I do that.
Should I run a web-socket client in the background? If so, how to integrate the web-socket client with the Django application.
Is Celery something that I should look into? I was looking into this for the past few hours. Went through a lot of questions. I am not able to figure out the right approach to do that.
You would need a TCP socket.
You will figure out more here: https://realpython.com/python-sockets/
Related
I use angular client side (TS) and Django server side (PY).
Unfortunately despite what I find on the internet, I can't send a message to a SPECIFIC client from the server. Socket.io doesn't exist in PY, I've seen the websockets but that only talks about sending a message to ALL clients in a group. But if I want to send a message only to a client B I don't see how to do it.
Please help me, and guide me on the solution to use
PS: I'm starting with the PY backend, be indulgent.
Thank you.
I’m currently trying to serve multiple bots (running different models) and to allow users to interact with it on a website. I’ve had a look at the following: http://www.rasa.com/docs/nlu/http/, http://www.rasa.com/docs/core/http/ and http://www.rasa.com/docs/nlu/python/, but I’m still having trouble figuring out how it can be done.
Some of the solutions I’ve considered are either:
Serve the bot on a HTTP server and have my website interact with the Rasa HTTP server
Create the website on Django Framework or REST API, and run Rasa Core and NLU on the backend.
What would be the best way to go about doing this? And, could anyone please briefly explain how this can be done (with multiple bot models and instances running)?
Any help would be greatly appreciated!
For anyone else searching for an answer, I ended up using Flask as the server, along with Flask-SocketIO for real time communication. The server serves an API which allows clients to communicate with it via SocketIO, determines which bot to interact with, gets the response, and sends it back to the client.
I am having trouble finding an answer to this question.
I am looking for a framework where I can send a python function to a rest endpoint, and it sends a response upon completion.
If there is no precanned solution, what would be a good set of packages to use to do this?
Maybe you could try to use SocketIO with Celery.
SocketIO is an option to create a channel between clients (web, mobile apps, etc) and server.
When received a specific message (you can create you own protocol) you can call a task in a Message Queue using Celery framework with Redis or RabbitMQ.
Maybe you need to use an another framework called Kombu to be able to send a message using the connection in socketio.
You can find some tips on this link: http://python-socketio.readthedocs.io/en/latest/
I hope I could helped.
currently, I have a little script that receives a lot of information through various channels using ZeroMQ PUB-SUB sockets.
What i want to do is: receive the info with zmq, process it, and then, send it away through a WebSocket, in order to be able to use it in an AngularJS application, displaying real time information.
All the websocket libraries i have found for python work in an asynchronous way, where i can send messages as a responde to a message the browser send in advance. I don't want to send messages as a response, i want to stream all the information I am receiving, for any instance of my AngularJS app that might be running.
Thanks in advance.
EDIT: I forgot something. I found this How do I stream data through a flask application?, and got it working with flask, but it seems to only work with the flask app from which the websocket is created, i can't connect to it from angular.
One good example is on Miguel Grinberg blog here. He creates a flask backend and uses Angular on front-end.
After the browser open the channel, the back end can send messages any time, without any constraints related to timing.
This might seem a lame question, but would be great if someone can help. I wrote a small python script which returns some output based on a command sent to it via slack's custom bot. Python script uses RTM API. Whenever someone in slack mentions the bot and passes a command (ex: #slackcustombot foobar), it returns a custom message(ex: Hi foobar) from the script. Now the issue is at the security side. My script resides at a server which is not open to internet. And as Slack uses dynamic IP, there's no possibility of white-listing the slack ip's.
So basically, all I wanted to know is, when someone in slack channel mentions the bots, and when the bot at slack server sends the command to my python script residing at my server, does it send as GET method or as POST method? cuz if it's a GET method, I might not have to worry about the security issue. but if it sends as POST method, what alternative I could use in this scenario? Any help is appreciated. Please correct me if I am wrong somewhere, still learning. :)
Regards,
Junaid.
Neither. It uses the WebSocket protocoll. If you rather want to use a HTTP-based protocol I would recommend looking into the Slack's Event API. It uses HTTPS POST to transfer messages to your bot.
The Events API is not providing all event types that are available with the RTM API, but its much easier to handle and should be sufficient for a chat bot. Check here for a documentation of which event types are available to the both RTM API and Events API.
You will however need to find a way to expose the url of your bot to the Internet, so that Slack can use it. If you need to access internal company applications through your Slack bot, the best approach in my opinion is to have the Slack bot on a webserver in the DMZ of your company.
A more small scale approach is to use a forwarding provider that is connecting to your local webserver through a VPN tunnel and exposing your internal webserver through a special public URL. That would work if you want Slack to talk to your webserver on a local network behind a router / firewall. One example is ngrok, but they are other providers too.