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

Getting started interactive message example does not work. #163

Closed
4 tasks done
sfroestl opened this issue Apr 24, 2019 · 6 comments · Fixed by #166 or #169
Closed
4 tasks done

Getting started interactive message example does not work. #163

sfroestl opened this issue Apr 24, 2019 · 6 comments · Fixed by #166 or #169
Labels
bug M-T: confirmed bug report. Issues are confirmed when the reproduction steps are documented

Comments

@sfroestl
Copy link
Contributor

Description

Hey!
First, thanks for the great project. 🚀

I've tried the getting started interactive message example but I can't make it work so that the button_click listener is invoked. See the code here https://github.com/sfroestl/bolt-example/blob/master/src/app.js
I've configured both Interactive Components and Events API of my slack app to point to /slack/events.
The message listener works fine.

https://slack.dev/bolt/tutorial/getting-started

What type of issue is this?

  • bug

Requirements

  • 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

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

Reproducible code in:

https://github.com/sfroestl/bolt-example

package version: 1.0.0

node version: v10.15.1

OS version(s): MacOs 10.14.4

Steps to reproduce:

  1. Clone repo https://github.com/sfroestl/bolt-example and $ npm i && npm start
  2. Enter slack and send the bot a message with "Hi".
  3. Click button.

Expected result:

Callback to be executed.

app.action('button_click', ({ action, say }) => {
  say(`@{action.user} clicked the button`);
});

Actual result:

The handler is not executed

Thanks a lot for your help!

@aoberoi aoberoi added the bug M-T: confirmed bug report. Issues are confirmed when the reproduction steps are documented label Apr 24, 2019
@aoberoi
Copy link
Contributor

aoberoi commented Apr 24, 2019

I've been able to reproduce this issue with a simple button block action. Here is my code:

const { App } = require('@slack/bolt');

const app = new App({
  token: process.env.SLACK_BOT_TOKEN,
  signingSecret: process.env.SLACK_SIGNING_SECRET,
});

app.message('hello', ({ say }) => {
  say({
    blocks: [{
      type: 'section',
      text: {
        type: 'mrkdwn',
        text: 'You can add a button alongside text in your message. ',
      },
      accessory: {
        type: 'button',
        action_id: 'foo',
        text: {
          type: 'plain_text',
          text: 'Button',
          emoji: true,
        },
        value: 'click_me_123',
      },
    }],
  });
});

app.action('foo', ({ ack }) => {
  console.log('action listener called');
  ack();
});

(async () => {
  const server = await app.start(process.env.PORT || 3000);
  console.log('⚡️ Bolt app is running!', server.address());
})();

Here is the output:

⚡️ Bolt app is running! { address: '::', family: 'IPv6', port: 3000 }
[ERROR]   { Error: An incoming event was not acknowledged before the timeout. Ensure that the ack() argument is called in your listeners.
    at receiverAckTimeoutError (/Users/ankur/Developer/play/bolt-demos/first-release/node_modules/@slack/bolt/dist/ExpressReceiver.js:167:19)
    at Timeout.setTimeout [as _onTimeout] (/Users/ankur/Developer/play/bolt-demos/first-release/node_modules/@slack/bolt/dist/ExpressReceiver.js:39:32)
    at ontimeout (timers.js:436:11)
    at tryOnTimeout (timers.js:300:5)
    at listOnTimeout (timers.js:263:5)
    at Timer.processTimers (timers.js:223:10) code: 'slack_bolt_receiver_ack_timeout_error' }

Notice that the action listener called output never appears.


We had an issue with block action (or interactive message) detection. Specifically, the incoming action (potentially a block action, interactive message, dialog submission, or message action) is supposed to go through the following function, which is supposed to detect whether its of the two types we're trying to identify. In this case, this detection gives us the wrong answer.

https://github.com/slackapi/bolt/blob/1ed27bbfbf2bd196723aafeccdf299e6b26f4bac/src/App.ts#L481-L485

The action property that its checking should be actions.

This is the kind of issue that TypeScript's typechecker is supposed to help us ensure that it doesn't happen. It's the reason we went through a lot of effort to write types for all these objects. However, in this case we defeated ourselves by leaving many objects "open ended", using the StringIndexed interface in places where we weren't sure if there would be additional properties added later.

I'm starting to think that we should remove StringIndexed from usages that make it easy to shoot ourselves in the foot (like this one). I've got a PR to share shortly.

@shaydewael
Copy link
Contributor

We just published v1.0.1 which should fix this @sfroestl 🎉

@sfroestl
Copy link
Contributor Author

Great work @shanedewael, @aoberoi. Much appreciated! I saw you also fixed the body.user.id in the acknowledge sample code. 👍

app.action('button_click', ({ body, ack, say }) => {
  // Acknowledge the action
  ack();
  say(`<@${body.user.id}> clicked the button`);
});

@i-break-codes
Copy link

@sfroestl wow... thank you..

@shaydewael you guys should really consider upgrading the documentation. Just spent 3 hours trying to figure out how do I get the user details in the action payload. Had hacked it out by attaching the user id I found from the command via context until I came across the body import.

@MattB543
Copy link

MattB543 commented Dec 9, 2020

@sfroestl

@i-break-codes

I also just spent an hour trying to get the user that clicked a button, couldn't see any documentation that showed how to get the payload of the block_action, only the payload of the action which doesn't have the user data. Maybe I missed it, it's possible, but this comment just saved me 🙏

@stevengill
Copy link
Member

@MattB543 sorry about that! You are totally right that we don't have a section in our docs for this. We hope to add some reference docs to tackle this soon. We do have a section in the readme for it over at https://github.com/slackapi/bolt-js#making-things-happen

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