Hubot Slack机器人商店可以举办会议吗 [英] Can Hubot Slack bot store sessions

查看:106
本文介绍了Hubot Slack机器人商店可以举办会议吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实现简单的Slack机器人.因此,我配置了hubot,它将接收来自slack的输入并将其传递到我的web应用程序(django app),它将接收来自django-app的所有响应并回复松弛.

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 app) and it will take whatever the response from django-app and will reply to slack.

在此过程中,我尝试使用request.session将会话存储在django中,但这未反映在slack中.如果我在浏览器中访问django-url,它将能够存储会话并获得正确的会话响应.

In this process I am trying to store session in django using request.session but that is not reflected in slack. If I am accessing the django-url in browser it is able to store sessions and getting proper response with session.

问题是否出在slack还是我的方法上?当请求django-app ??

So does the problem lie with slack or my approach and is there a way to store sessions in hubot when requesting to django-app ??

推荐答案

我无法说出您使用的特定技术(hubot,django),但是我一直在与Slack应用程序一起使用服务器会话,并且可以为您提供服务关于其工作原理的一般答案.请注意,我的Slack应用是使用PHP构建的,但是我认为可以放心地假设原理是相同的.

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不支持会话

通常,Slack不支持会话或上下文.相反,所有内容都是基于请求的.因此,如果您希望进行会话以在请求之间保持功能性上下文,则需要在Slack应用中自行进行组织.

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.

将服务器会话与服务器请求一起使用的挑战

一个挑战是,大多数服务器会话都旨在与使用浏览器的客户端一起使用.例如一个PHP服务器会话将在浏览器中存储一个cookie,因此服务器知道哪些请求属于同一会话.这显然不适用于Slack,因为所有Slack请求均来自服务器,并且不涉及浏览器.

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.

通过Slack使用服务器会话的方法

但是您可以通过以下两个技巧将Svers会话与Slack结合使用:

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

手动设置会话ID

通常,服务器会自动选择会话的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.

在Slack控件中包含会话ID

用户的功能会话由他使用的Slack控件绑定在一起. (例如,交互式按钮).可以在这些控件中包含自定义数据(有关详细信息,请参见此答案),并允许您包含当前会话ID在里面.

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.

完全方法

您将当前会话的ID包含在您使用应用创建的Slack控件中(例如,交互式按钮).用户单击按钮后,Slack将向您的应用发送请求,其中将包含会话ID.这样一来,您的应用就可以继续已经启动的服务器会话.

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.

这篇关于Hubot Slack机器人商店可以举办会议吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆