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

Cannot use Custom SocketMode Receiver #1180

Closed
5 of 10 tasks
M1kep opened this issue Oct 28, 2021 · 4 comments
Closed
5 of 10 tasks

Cannot use Custom SocketMode Receiver #1180

M1kep opened this issue Oct 28, 2021 · 4 comments
Labels
needs info An issue that is claimed to be a bug and hasn't been reproduced, or otherwise needs more info question M-T: User needs support to use the project

Comments

@M1kep
Copy link
Contributor

M1kep commented Oct 28, 2021

Description

When I attempt use a custom SocketMode receiver when creating a new App instance, it throws an error.

It looks like this PR added the throw that now conflicts with the documentation:
image

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

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • example code 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

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

Reproducible in:

package version:3.7.0

node version: v16.9.1

Typescript Version: 4.4.3

OS version(s): macOS Monterey - 12.0.1 (21A559)

@M1kep
Copy link
Contributor Author

M1kep commented Oct 28, 2021

This issue is related to #1179 as this is the only workaround I can think of at the moment

@srajiang
Copy link
Member

srajiang commented Oct 28, 2021

@M1kep - So I thought I could recreate an error using the documentation code sample, but was mistaken. Could you provide the error + the app initialization code you're using?

If you're using a custom SocketModeReceiver, you should not set socketMode:true, otherwise you'll correctly get the error you referenced.

The app initializes for me with the below:

const { App, SocketModeReceiver } = require('@slack/bolt');
require('dotenv').config();

const socketModeReceiver = new SocketModeReceiver({
  appToken: process.env.SLACK_APP_TOKEN,
});

const app = new App({
  receiver: socketModeReceiver,
  // disable token line below if using OAuth
  token: process.env.SLACK_BOT_TOKEN
});

(async () => {
  await app.start();
  console.log('⚡️ Bolt app started');
})();

Let me know if I'm missing something!

@srajiang srajiang added needs info An issue that is claimed to be a bug and hasn't been reproduced, or otherwise needs more info question M-T: User needs support to use the project labels Oct 28, 2021
@M1kep
Copy link
Contributor Author

M1kep commented Oct 29, 2021

@srajiang So, I've messed around this this a little bit more and have it working. The two issues were the AppOptions.socketMode not being set to false and not providing the customRoutes to the SocketModeReceiver constructor.

I'm able to get it functioning with the AppOptions.socketMode set to false, and using a custom SocketModeReceiver with the customRoutes and port option set:

import {config} from 'dotenv';
import {App, SocketModeReceiver} from "@slack/bolt";

config({path: './.env'})

const socketModeReceiver = new SocketModeReceiver({
        // @ts-ignore Ignore the possibly undefined environment variable as this is just an example
        appToken: process.env.APP_TOKEN,
        // disable token line below if using OAuth
        token: process.env.BOT_TOKEN,
        signingSecret: process.env.SIGNING_SECRET,
        customRoutes: [
            {
                method: 'GET',
                handler: (req, res) => {
                    console.log(req.headers);
                    console.log('HTTP Hit! - /test');
                    res.end();
                },
                path: '/test'
            }
        ],
        installerOptions: {
            port: 8080,
        }
    }
);

const app = new App({
    receiver: socketModeReceiver,
    // @ts-ignore Ignore the possibly undefined environment variable as this is just an example
    appToken: process.env.APP_TOKEN,
    // disable token line below if using OAuth
    token: process.env.BOT_TOKEN,
    signingSecret: process.env.SIGNING_SECRET,
});

(async () => {
    await app.start();
    console.log('⚡️ Bolt app started');
})();

Result:

❯ lsof -nP -iTCP -sTCP:LISTEN | grep 8080
node      24430 user   73u  IPv6 0xb386ab51bd665a39      0t0  TCP *:8080 (LISTEN)

❯ http localhost:8080/test
HTTP/1.1 200 OK
Connection: keep-alive
Date: Thu, 28 Oct 2021 23:51:53 GMT
Keep-Alive: timeout=5
Transfer-Encoding: chunked

HIT!

@seratch
Copy link
Member

seratch commented Oct 29, 2021

@M1kep It's great to hear that you've figured out how to configure the receiver! Let us close this issue now.

@seratch seratch closed this as completed Oct 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs info An issue that is claimed to be a bug and hasn't been reproduced, or otherwise needs more info question M-T: User needs support to use the project
Projects
None yet
Development

No branches or pull requests

3 participants