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

When receiving a bot writing message using the User OAuth Token, the res.message.user has room property only #615

Closed
4 of 9 tasks
buzztaiki opened this issue Dec 26, 2020 · 5 comments · Fixed by #617
Closed
4 of 9 tasks
Labels
bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented good first issue
Milestone

Comments

@buzztaiki
Copy link
Contributor

Description

When receiving a bot writing message using the User OAuth Token, the res.message.user has room property only.
I expect it is user object. Until hubot-slack 4.5.5, it is user object in this situation.

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • testing related
  • discussion

Requirements (place an x in each of the [ ])

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

Bug Report

Reproducible in:

hubot-slack version: 4.8.1

node version: 15.4.0

OS version(s):

uname -a
Linux echo 5.9.14-arch1-1 #1 SMP PREEMPT Sat, 12 Dec 2020 14:37:12 +0000 x86_64 GNU/Linux

Steps to reproduce:

  1. Run following hubot script:

    module.exports = (robot) ->
      robot.hear /show me/i, (res) ->
        console.log(res.message.user)
        res.send JSON.stringify(res.message.user, null, 2)
    
  2. Create slack app (not hobot)

    • User Token Scopes:
      • chat:write
  3. Install slack app to my workspace.

  4. Copy [OAuth Access Token] value.

  5. Run following script

    const { WebClient } = require("@slack/client")
    
    const web = new WebClient(process.env.SLACK_USER_TOKEN)
    web.chat.postMessage({
      channel: process.env.SLACK_CHANNEL,
      text: "show me",
    })
    

Expected result:

I expect get a user object from res.message.user.

User {
  id: 'U2C95QECR',
  name: 'buzztaiki',
  real_name: 'Taiki Sugawara',
  slack: {
    ...
  }
}

Actual result:

res.message.user has room property only.

{ room: 'C2C91PE5T' }

Attachments:

@gitwave gitwave bot added the untriaged label Dec 26, 2020
@buzztaiki
Copy link
Contributor Author

Is it correct patch?

diff --git a/src/client.coffee b/src/client.coffee
index 98e27ab..432f253 100644
--- a/src/client.coffee
+++ b/src/client.coffee
@@ -332,10 +332,10 @@ class SlackClient
     if @eventHandler
       # fetch full representations of the user, bot, and potentially the item_user.
       fetches = {}
-      if event.bot_id
-        fetches.bot = @fetchBotUser event.bot_id
-      else if event.user
+      if event.user
         fetches.user = @fetchUser event.user
+      else if event.bot_id
+        fetches.bot = @fetchBotUser event.bot_id
       if event.item_user
         fetches.item_user = @fetchUser event.item_user

@buzztaiki
Copy link
Contributor Author

This patch has been worked in my environment and situation.

buzztaiki added a commit to smartoperation/hubot-slack that referenced this issue Dec 27, 2020
@seratch
Copy link
Member

seratch commented Dec 28, 2020

@buzztaiki Thanks for taking the time to report this. I've confirmed that the payload for messages posted using a user token includes bot_id and bot_profile. Therefore, as you pointed out, the current logic does not work with it.

{
  "bot_id": "B111",
  "suppress_notification": false,
  "type": "message",
  "text": "thanks a lot",
  "user": "U111",
  "team": "T111",
  "bot_profile": {},
  "source_team": "T111",
  "user_team": "T111",
  "channel": "C111",
  "event_ts": "1609114401.001400",
  "ts": "1609114401.001400"
}

Regarding the fix, it looks great to me. If you don't mind, could you send a pull request?

@seratch seratch added bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented good first issue and removed untriaged labels Dec 28, 2020
@seratch seratch added this to the 4.8.2 milestone Dec 28, 2020
@buzztaiki
Copy link
Contributor Author

could you send a pull request?

Sorry, I missed look at your comment. I will send PR.

@buzztaiki
Copy link
Contributor Author

@seratch I've create PR #617

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented good first issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants