Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hubot doesn't react on direct messages when talking directly to him with @myhubot #5

Closed
daconstenla opened this issue Jan 28, 2019 · 12 comments · Fixed by #11
Closed
Assignees

Comments

@daconstenla
Copy link

Hi all, I've been playing around with hubot integration of hangouts chat and is not working is said in the documentation, according to it, hubot should answer back on any mention as:

MYHUBOT help
myhubot help
@myhubot help
myhubot: help

but with google chat integration bot only reacts when it's mentioned with @ when it's mentioned twice, for example:

@myhubot myhubot help

after enabling DEBUG=true I've seen that in the received body is getting the raw message as text field but it's processing the field argumentedText which strips user's mention.

possible solution

I've made a small change on the HangoutsChatTextMessage object creation to use received message.text and then it works as expected, any reason why on the implementation the object is being created with argumentText? I haven't seen any difference but mentioned removed from the message.

raw json body of an example message with mention

...
        "text": "@myhubot help",
        "annotations": [
            {
                "type": "USER_MENTION",
                "startIndex": 0,
                "length": 8,
                "userMention": {
                    "user": {
                        "name": "users/USER-ID",
                        "displayName": "myhubot",
                        "avatarUrl": "https://lh4.googleusercontent.com/proxy/URL",
                        "type": "BOT"
                    },
                    "type": "MENTION"
                }
            }
        ],
        "thread": {
            "name": "spaces/THREAD-ID,
            "retentionSettings": {
                "state": "PERMANENT"
            }
        },
        "space": {
            "name": "spaces/SPACE-ID",
            "type": "ROOM",
            "displayName": "test-room"
        },
        "argumentText": " help"
...

Thanks!

@kumarse kumarse assigned dgliu-f82 and unassigned kumarse Jan 29, 2019
daconstenla pushed a commit to smava/hubot-google-hangouts-chat that referenced this issue Jan 30, 2019
avoiding the mentions to be removed from the message itself
@dgliu-f82
Copy link
Contributor

@daconstenla were you trying this in a DM or Room?
In a room, Hangouts Chat doesn't invoke a bot unless it's explicitly @mention'ed by the user.
In a DM, every user message is sent to the bot since there's no other entity involved.
message.text is the raw text from user and argumentText is raw text minus the @mention part. Therefore, argumentText is the correct one to use.

@joeyguerra
Copy link
Contributor

I'm having the same problem. Perhaps I'm misunderstanding how this works. Should the regex pattern to match a handler include the bot's name in it? for example, if the bot name is pipbot, should the regex pattern to match handlers include ^\s*[@]?pipbot[:,]?\s* in it?

@daconstenla
Copy link
Author

@joeyguerra check the changes I made on the branch issue-5, by doing that, bot answers to my messages since message has the name of the bot on the message, otherwise is stripped from the message.

@dgliu-f82 I've tried with both approaches, DM's and Rooms, either way doesn't work as expected unless my change is applied.

@joeyguerra
Copy link
Contributor

Yeah. Especially after reading this:

  // at the robot based on a Regex. All regexes treat patterns like they begin
  // with a '^'
  //
  // regex    - A Regex that determines if the callback should be called.
  // options  - An Object of additional parameters keyed on extension name
  //            (optional).
  // callback - A Function that is called with a Response object.
  //
  // Returns nothing.
  respond (regex, options, callback) {
    this.hear(this.respondPattern(regex), options, callback)
  }

i believe using text instead of argumentText is correct. Because text will have the bot name included which is what the code expects for respond to work as designed.

@joeyguerra
Copy link
Contributor

@daconstenla did you accept the code commit agreement? Gotta do that first.

@daconstenla
Copy link
Author

I want to but since I did the contribution during working hours, I theoretically did the contribution as "company" and so I need my company to agree with the license before clicking the button 🤔

@joeyguerra
Copy link
Contributor

maybe @dgliu-f82 can make the change instead of accepting the pull request then?

@dgliu-f82
Copy link
Contributor

I believe the regex shouldn't contain the bot's name according to Hubot API. See the examples here:
https://hubot.github.com/docs/scripting/
The regex should match the user's message after the @mention part.

@joeyguerra
Copy link
Contributor

Unfortunately, the code assumes that the bot's name is in the text.

^\s*[@]?pipbot[:,]?\s*

gets prepended to the regex pattern that the scripts set (where pipbot is the name of the bot).

@dgliu-f82
Copy link
Contributor

I see. I missed the difference between hear and respond earlier. For respond, Hubot automatically prepends the robot's name into the regex passed by the caller in order to match only messages directed at the bot. I think it does make sense for the Hangouts Chat adapter to pass the original text instead of argumentText. We will update the code shortly.

@dgliu-f82
Copy link
Contributor

Just to clarify though, Hangouts Chat today doesn't invoke a bot unless it's @mentioned in a room as I mentioned earlier #5 (comment).
Switching to text from argumentText makes the adapter more aligned with Hubot API and will make robot.respond work. However, there's no difference between hear and respond for a Chat bot in a room currently. There is a distinction in a bot DM, but most users don't explicitly @mention the bot in DM since every message is directed at the bot already.

@joeyguerra
Copy link
Contributor

Yeah, that's where the design of Hubot and integrations design of Google Chat are not congruent. Which is exactly what the Adapter Pattern is supposed to solve. And in this case, I feel like this module should adapt Google Chat's integration designs to conform to Hubots design.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants