Can Hubot Slack bot store sessions

前端 未结 1 1008
粉色の甜心
粉色の甜心 2021-01-15 17:56

I am trying to implement simple slack bot. So I have configured hubot which will take inputs from slack and passing it to my webapp (django a

1条回答
  •  抹茶落季
    2021-01-15 18:30

    I can not speak to the specific technologies you use (hubot, django), but I am using server sessions with my Slack apps all the time and can give you a general answer on how it works. Note that my Slack apps are build with PHP, but I think its safe to assume that the principles are the same.

    Slack does not support sessions

    In general Slack does not support sessions or context. Instead everything is request based. So if you want to have sessions to keep a functional context between requests you need to organize that by yourself in your Slack app.

    Challenge for using server sessions with server requests

    One challenge is that most server sessions are designed to work with a client that uses a browser. e.g. a PHP server session will store a cookie in the browser, so the server knows, which requests belong to the same session. This does obviously not work with Slack, since all Slack requests are coming from a server and and there is no browser involved.

    Approach for using server sessions with Slack

    But you can use severs session with Slack with these two tricks:

    Manually set the session ID

    Usually the ID of a session is chosen automatically by the server, but you can also set it manually. This allows you to tell the server to continue an existing session that was started with a previous request.

    Include session ID in Slack control

    The functional session of a user is tied together by the Slack controls he uses. (e.g. an interactive button). Its possible to include custom data in those controls (see this answer for details) and that allows you to include the current session ID in it.

    Full approach

    You include the ID of your current session in the Slack controls, that you create with your app (e.g. an interactive button). Once the user clicks a button Slack will send a request to your app, which will include the session ID. That allows your app to continue an already started server session.

    0 讨论(0)
提交回复
热议问题