Bolt-js: mention app to do action

Created on 23 Feb 2020  Β·  12Comments  Β·  Source: slackapi/bolt-js

Description

Hi ,

I'm using bolt v1.5 to create slack app with home tab . I need when user mentions my app (ex: @my_app) it replies with an interactive message for list of commands used . I tried to implement app_mention event but it didn't work (the event is not firing ) although i added app_mention:read at Bot Token scopes permissions .
Am i missing something at permissions or i'm using the wrong event ?

Regards ,
Marwa

Describe your issue here.

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

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

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

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

Bug Report

Filling out the following details about bugs will help us solve your issue sooner.

Reproducible in:

package version:

node version:

OS version(s):

Steps to reproduce:

1.
2.
3.

Expected result:

What you expected to happen

Actual result:

What actually happened

Attachments:

Logs, screenshots, screencast, sample project, funny gif, etc.

question

Most helpful comment

Glad you got it working @MarwaAbuEssa πŸ™Œ

All 12 comments

@MarwaAbuEssa Hey there πŸ‘‹Is your app in the channel where it's being mentioned? The app_mentions:read scope only fires when it is in the channel.

hi @shaydewael ,

the app is installed in a certain channel and yes i'm trying to mention the app at app's messages tab . is there any other event to use ?

Thanks

@MarwaAbuEssa It seems that app_mentions:read only allows your app to listen to public channels. To listen to messages within your app's messages tab, you'll have to subscribe to the message.im event.

In Bolt, if you wanted to filter out messages that mention your app, you could write a handler similar to this:

app.message('@APP_ID', ({ context, payload }) => {
  console.log(payload);
});

hi @shaydewael
unfortunate , it didn't work
here is a list of all scopes and permissions added to my app

Bot Token Scopes

  1. app_mentions:read
  2. channels:history
  3. channels:manage
  4. channels:read
  5. chat:write
  6. commands
  7. groups:history
  8. im:history
  9. im:read
  10. im:write
  11. links:read
  12. mpim:history

User Token Scopes

  1. channels:read
  2. channels:write
  3. chat:write
  4. im:history
  5. im:read
  6. im:write
  7. users:read
  8. users:write

Thanks a lot for your help

Hmm that's weird πŸ€” What events are you subscribed to (under the Event Subscriptions tab)? I got the code example I posted to work locally

HI @shaydewael i know it's weird indeed 😊
image

image

may be because Subscribe to events on behalf of users is empty ?
Thanks in advance

@MarwaAbuEssa Looks like you're subscribed to the correct events β€” you shouldn't have to subscribe to any Workspace Events. Is your app receiving any events at all? If not, you may want to double-check your Request URL at the top of that page. Bolt always listens at the /slack/events endpoint, so if my app was hosted at https://sample-app.ngrok.io, my Request URL would be http://sdewael-bolt.ngrok.io/slack/events.

Although if you're adding events, I assume your Request URL is verified and working. Is there any information in the Bolt logs (like errors, or warning messages)?

hi @shaydewael ,
yes i'm receiving app_home_opened event which is working perfectly with all event data. also i'm using 3 commands and it is working perfectly .!! .
well the console log at event function (for app mention of app.message) is not logging anything as if it didn't goes into the function at all and also the console is not throws any error . may be i should add try and catch and try it again and kindly send me if you have any news.

Thanks in advance

@MarwaAbuEssa Adding the following code (a middleware for debug logging) in your app may be helpful. The debug log captures all incoming requests from Slack. You can check if your app is properly configured to receive those events more easily.

app.use(args => {
  const copiedArgs = JSON.parse(JSON.stringify(args));
  copiedArgs.context.botToken = 'xoxb-***';
  if (copiedArgs.context.userToken) {
    copiedArgs.context.userToken = 'xoxp-***';
  }
  copiedArgs.client = {};
  copiedArgs.logger = {};
  args.logger.info(
    "Dumping request data for debugging...\n\n" +
    JSON.stringify(copiedArgs, null, 2) +
    "\n"
  );
  args.next();
});

hi @seratch ,

Thanks a lot i will add the debugging code and see the results

hi @shaydewael ,
It worked now !! its my mistake , when you send me the code app.message('@APP_ID', ({ context, payload }) => { console.log(payload); }); i was adding @app_name at the param not @app_uniqueid which is the app id actually 😊 i'm so sorry for inconvenience .

hi @seratch , thank you so much for the logger code , i wish i had it long time ago πŸ‘ 😊

Thanks a lot for your awesome support .

Glad you got it working @MarwaAbuEssa πŸ™Œ

Was this page helpful?
0 / 5 - 0 ratings