简体   繁体   English

如何让Hubot知道他/她在私聊中收到消息?

[英]How to make Hubot know he/she is receiving the message in a private chat?

I am creating a Hubot script to do some stuffs. 我正在创建一个Hubot脚本来做一些事情。 However due to some circumstances, we need to make sure certain commands only works when sent via PM (private message) instead of channels (eg telling the bot to save some password). 但是由于某些情况,我们需要确保某些命令仅在通过PM(私人消息)而不是通道发送时才起作用 (例如告诉机器人保存一些密码)。

As a workaround, I am currently using this checker function: 作为一种解决方法,我目前正在使用此检查功能:

is_private = (res) -> res.message.room == res.message.user.name

We are currently using this with Slack, but need to make the script also works with other adapters as well since we're going to release it as open source project. 我们目前正在使用Slack,但需要使脚本也可以与其他适配器一起使用 ,因为我们将把它作为开源项目发布。

Is this method reliable enough? 这种方法足够可靠吗? Is there any built-in methods to check this? 有没有内置方法来检查这个?

In your case, consider use hubot-auth to control permissions for your users 在您的情况下,请考虑使用hubot-auth来控制用户的权限

https://www.npmjs.com/package/hubot-auth https://www.npmjs.com/package/hubot-auth

or 要么

How to setup Hubot basic permissions? 如何设置Hubot基本权限?

The Adapter interface is mum on private messages (Campfire, the first adapter, has absolutely no support for PMs). 适配器接口是私人消息(Campfire,第一个适配器,绝对不支持PM)。 I think your method will work fine for most adapters, but cross-adapter PM behavior is an ongoing issue. 我认为你的方法适用于大多数适配器,但是交叉适配器PM行为是一个持续的问题。 Maybe, sometime, I'll get to work on the Adapter interface, but most of my effort is currently focused on the message processing flow. 也许,有时候,我会开始使用Adapter接口,但我目前的大部分工作都集中在消息处理流程上。

I'd recommend going with it and keeping an eye out for issues after you release. 我建议您在发布后继续使用它并留意问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM