简体   繁体   中英

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. 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).

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.

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

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

or

How to setup Hubot basic permissions?

The Adapter interface is mum on private messages (Campfire, the first adapter, has absolutely no support for PMs). I think your method will work fine for most adapters, but cross-adapter PM behavior is an ongoing issue. Maybe, sometime, I'll get to work on the Adapter interface, but most of my effort is currently focused on the message processing flow.

I'd recommend going with it and keeping an eye out for issues after you release.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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