Coder Social home page Coder Social logo

sample-message-menus-node's Introduction

Message Menus API Sample for Node

Message menus are a feature of the Slack Platform that allow your Slack app to display a set of choices to users within a message.

This sample demonstrates building a coffeebot, which helps you customize a drink order using message menus.

Demo

Start by DMing the bot (or it will DM you when you join the team). Coffeebot introduces itself and gives you a message button to start a drink order. Coffees can be complicated so the bot gives you menus to make your drink just right (e.g. mocha, non fat milk, with a triple shot). It sends your completed order off to a channel where your baristas are standing by.

You can either develop this app locally or you can Remix on Glitch

Setup

Create a Slack app

To start, create an app at api.slack.com/apps and configure it with a bot user, event subscriptions, interactive messages, and an incoming webhook. This sample app uses the Slack Event Adapter, where you can find some configuration steps to get the Events API ready to use in your app.

Bot user

Click on the Bot user feature on your app configuration page. Assign it a username (such as @coffeebot), enable it to be always online, and save changes.

Event subscriptions

Turn on Event Subscriptions for the Slack app. You must input and verify a Request URL, and the easiest way to do this is to use a development proxy as described in the Events API module. The application listens for events at the path /slack/events:

  • ngrok or Glitch URL + /slack/events

Create a subscription to the team event team_join and a bot event for message.im. Save your changes.

Interactive Messages

Click on Interactive Messages on the left side navigation, and enable it. Input your Request URL:

  • ngrok or Glitch URL + /slack/actions

(there's a more complete explanation of Interactive Message configuration on the Node Slack Interactive Messages module).

Incoming webhook

Create a channel in your development team for finished coffee orders (such as #coffee). Add an incoming webhook to your app's configuration and select this team. Complete it by authorizing the webhook on your team.

Environment variables

You should now have a Slack verification token (basic information), access token, and webhook URL (install app).

You can develop the app locally by cloning this repository. Or you can Remix on Glitch

If you're developing locally:

  1. Create a new file named .env (see .env.sample) within the directory and place the values as shown below
  2. Download the dependencies for the application by running npm install. Note that this example assumes you are using a currently supported LTS version of Node (at this time, v6 or above).
  3. Start the app (npm start)

If you're using Glitch:

  1. Enter the enviornmental variables in .env as shown below
SLACK_VERIFICATION_TOKEN=xxxxxxxxxxxxxxxxxxx
SLACK_BOT_TOKEN=xoxb-0000000000-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
SLACK_WEBHOOK_URL=https://hooks.slack.com/services/xxxxxxxxx/yyyyyyyyy/zzzzzzzzzzzzzzzzzzzzzzzz

Usage

Go ahead and DM @coffeebot to see the app in action!

sample-message-menus-node's People

Contributors

aoberoi avatar colmdoyle avatar hwz avatar roach avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sample-message-menus-node's Issues

Missing dependency

Hello,
Missing file:
'@slack/interactive-messages' is not in the npm registry.

Getting method deprecated

When I run npm start, I get the following error:

> node index.js

server listening on port 3000
error: Response not OK:  method_deprecated
Error: method_deprecated
    at handleHttpResponse (/sample-message-menus-node/node_modules/@slack/client/lib/clients/transports/call-transport.js:103:17)
    at handleTransportResponse (/sample-message-menus-node/node_modules/@slack/client/lib/clients/transports/call-transport.js:153:19)
    at apply (/sample-message-menus-node/node_modules/lodash/lodash.js:478:17)
    at wrapper (/sample-message-menus-node/node_modules/lodash/lodash.js:5337:16)
    at Request.handleRequestTranportRes (/sample-message-menus-node/node_modules/@slack/client/lib/clients/transports/request.js:21:5)
    at apply (/sample-message-menus-node/node_modules/lodash/lodash.js:478:17)
    at Request.wrapper [as _callback] (/sample-message-menus-node/node_modules/lodash/lodash.js:5337:16)
    at Request.self.callback (/sample-message-menus-node/node_modules/request/request.js:186:22)
    at Request.emit (events.js:189:13)
    at Request.<anonymous> (/sample-message-menus-node/node_modules/request/request.js:1060:10)
    at Request.emit (events.js:189:13)
    at IncomingMessage.<anonymous> (/sample-message-menus-node/node_modules/request/request.js:980:12)
    at Object.onceWrapper (events.js:277:13)
    at IncomingMessage.emit (events.js:194:15)
    at endReadableNT (_stream_readable.js:1125:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)

The slackbot does not respond when I DM it. Any idea to resolve this?

Getting TypeError: Expected an options argument but instead received a string

image
@aoberoi
Whenever i tried sending message from slack app im getting below error in console where i ran my server

node index.js
@slack/events-api:adapter adapter instantiated - options: { includeBody: false, includeHeaders: false, waitForResponse: false } +0ms
@slack/interactive-messages:adapter instantiated +0ms
express:application set "x-powered-by" to true +17ms
express:application set "etag" to 'weak' +6ms
express:application set "etag fn" to [Function: generateETag] +4ms
express:application set "env" to 'development' +8ms
express:application set "query parser" to 'extended' +6ms
express:application set "query parser fn" to [Function: parseExtendedQueryString] +10ms
express:application set "subdomain offset" to 2 +5ms
express:application set "trust proxy" to false +8ms
express:application set "trust proxy fn" to [Function: trustNone] +15ms
express:application booting in development mode +3ms
express:application set "view" to [Function: View] +10ms
express:application set "views" to 'C:\Users\VenkateshGujjala\Music\Chatbots_with_python\OS_installation\Slack\message\views' +4ms
express:application set "jsonp callback name" to 'callback' +10ms
express:router use '/' query +6ms
express:router:layer new '/' +6ms
express:router use '/' expressInit +8ms
express:router:layer new '/' +7ms
express:router use '/' jsonParser +16ms
express:router:layer new '/' +21ms
express:router use '/webhooks/slack/webhook' slackEventAdapterMiddleware +12ms
express:router:layer new '/webhooks/slack/webhook' +10ms
express:router use '/' urlencodedParser +6ms
express:router:layer new '/' +10ms
express:router use '/webhooks/slack/actions' +4ms
express:router:layer new '/webhooks/slack/actions' +10ms
server listening on port 3000
express:router dispatching POST /webhooks/slack/webhook +14s
express:router query : /webhooks/slack/webhook +6ms
express:router expressInit : /webhooks/slack/webhook +4ms
express:router jsonParser : /webhooks/slack/webhook +7ms
body-parser:json content-type "application/json" +3ms
body-parser:json content-encoding "identity" +10ms
body-parser:json read body +12ms
body-parser:json parse body +55ms
body-parser:json parse json +4ms
express:router trim prefix (/webhooks/slack/webhook) from url /webhooks/slack/webhook +2ms
express:router slackEventAdapterMiddleware /webhooks/slack/webhook : /webhooks/slack/webhook +6ms
@slack/events-api:express-middleware request recieved - method: POST, path: / +8ms
@slack/events-api:express-middleware request token verification success +9ms
@slack/events-api:express-middleware sending response - error: undefined, responseOptions: {} +2ms
@slack/events-api:express-middleware response body: +12ms
@slack/events-api:express-middleware emitting event - type: message, arguments: [ { client_msg_id: 'a6a04f03-28ff-498e-9c9f-27aacf3012fd', type: 'message', text: 'hey', user: 'UJ8Q33JQ1', ts: '1573623071.001000', team: 'TJGV1B2MD', channel: 'DJGV51W79', event_ts: '1573623071.001000', channel_type: 'im' } ] +16ms
@slack/events-api:express-middleware response finished - status: 200, headers: [Object: null prototype] { 'x-powered-by': 'Express', 'x-slack-powered-by': '@slack:events-api/1.0.1 win32/10.0.17763 node/10.16.0', 'content-type': 'text/html; charset=utf-8', 'content-length': '0', etag: 'W/"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"' } +23ms
TypeError: Expected an options argument but instead received a string
at WebClient.apiCall (C:\Users\VenkateshGujjala\Music\Chatbots_with_python\OS_installation\Slack\message\node_modules@slack\web-api\dist\WebClient.js:414:19)
at Object.introduceToUser (C:\Users\VenkateshGujjala\Music\Chatbots_with_python\OS_installation\Slack\message\lib\bot.js:44:17)
at Object.handleDirectMessage (C:\Users\VenkateshGujjala\Music\Chatbots_with_python\OS_installation\Slack\message\lib\bot.js:193:12)
at SlackEventAdapter.slackEvents.on (C:\Users\VenkateshGujjala\Music\Chatbots_with_python\OS_installation\Slack\message\index.js:24:7)
at SlackEventAdapter.emit (events.js:198:13)
at slackEventAdapterMiddleware (C:\Users\VenkateshGujjala\Music\Chatbots_with_python\OS_installation\Slack\message\node_modules@slack\events-api\dist\express-middleware.js:160:20)
at Layer.handle [as handle_request] (C:\Users\VenkateshGujjala\Music\Chatbots_with_python\OS_installation\Slack\message\node_modules\express\lib\router\layer.js:95:5)
at trim_prefix (C:\Users\VenkateshGujjala\Music\Chatbots_with_python\OS_installation\Slack\message\node_modules\express\lib\router\index.js:317:13)
at C:\Users\VenkateshGujjala\Music\Chatbots_with_python\OS_installation\Slack\message\node_modules\express\lib\router\index.js:284:7
at Function.process_params (C:\Users\VenkateshGujjala\Music\Chatbots_with_python\OS_installation\Slack\message\node_modules\express\lib\router\index.js:335:12)

Getting TypeError: Expected an options argument but instead received a string

Whenever i tried sending message from slack app im getting below error in console where i ran my server

node index.js
@slack/events-api:adapter adapter instantiated - options: { includeBody: false, includeHeaders: false, waitForResponse: false } +0ms
@slack/interactive-messages:adapter instantiated +0ms
express:application set "x-powered-by" to true +17ms
express:application set "etag" to 'weak' +6ms
express:application set "etag fn" to [Function: generateETag] +4ms
express:application set "env" to 'development' +8ms
express:application set "query parser" to 'extended' +6ms
express:application set "query parser fn" to [Function: parseExtendedQueryString] +10ms
express:application set "subdomain offset" to 2 +5ms
express:application set "trust proxy" to false +8ms
express:application set "trust proxy fn" to [Function: trustNone] +15ms
express:application booting in development mode +3ms
express:application set "view" to [Function: View] +10ms
express:application set "views" to 'C:\Users\VenkateshGujjala\Music\Chatbots_with_python\OS_installation\Slack\message\views' +4ms
express:application set "jsonp callback name" to 'callback' +10ms
express:router use '/' query +6ms
express:router:layer new '/' +6ms
express:router use '/' expressInit +8ms
express:router:layer new '/' +7ms
express:router use '/' jsonParser +16ms
express:router:layer new '/' +21ms
express:router use '/webhooks/slack/webhook' slackEventAdapterMiddleware +12ms
express:router:layer new '/webhooks/slack/webhook' +10ms
express:router use '/' urlencodedParser +6ms
express:router:layer new '/' +10ms
express:router use '/webhooks/slack/actions' +4ms
express:router:layer new '/webhooks/slack/actions' +10ms
server listening on port 3000
express:router dispatching POST /webhooks/slack/webhook +14s
express:router query : /webhooks/slack/webhook +6ms
express:router expressInit : /webhooks/slack/webhook +4ms
express:router jsonParser : /webhooks/slack/webhook +7ms
body-parser:json content-type "application/json" +3ms
body-parser:json content-encoding "identity" +10ms
body-parser:json read body +12ms
body-parser:json parse body +55ms
body-parser:json parse json +4ms
express:router trim prefix (/webhooks/slack/webhook) from url /webhooks/slack/webhook +2ms
express:router slackEventAdapterMiddleware /webhooks/slack/webhook : /webhooks/slack/webhook +6ms
@slack/events-api:express-middleware request recieved - method: POST, path: / +8ms
@slack/events-api:express-middleware request token verification success +9ms
@slack/events-api:express-middleware sending response - error: undefined, responseOptions: {} +2ms
@slack/events-api:express-middleware response body: +12ms
@slack/events-api:express-middleware emitting event - type: message, arguments: [ { client_msg_id: 'a6a04f03-28ff-498e-9c9f-27aacf3012fd', type: 'message', text: 'hey', user: 'UJ8Q33JQ1', ts: '1573623071.001000', team: 'TJGV1B2MD', channel: 'DJGV51W79', event_ts: '1573623071.001000', channel_type: 'im' } ] +16ms
@slack/events-api:express-middleware response finished - status: 200, headers: [Object: null prototype] { 'x-powered-by': 'Express', 'x-slack-powered-by': '@slack:events-api/1.0.1 win32/10.0.17763 node/10.16.0', 'content-type': 'text/html; charset=utf-8', 'content-length': '0', etag: 'W/"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"' } +23ms
TypeError: Expected an options argument but instead received a string
at WebClient.apiCall (C:\Users\VenkateshGujjala\Music\Chatbots_with_python\OS_installation\Slack\message\node_modules@slack\web-api\dist\WebClient.js:414:19)
at Object.introduceToUser (C:\Users\VenkateshGujjala\Music\Chatbots_with_python\OS_installation\Slack\message\lib\bot.js:44:17)
at Object.handleDirectMessage (C:\Users\VenkateshGujjala\Music\Chatbots_with_python\OS_installation\Slack\message\lib\bot.js:193:12)
at SlackEventAdapter.slackEvents.on (C:\Users\VenkateshGujjala\Music\Chatbots_with_python\OS_installation\Slack\message\index.js:24:7)
at SlackEventAdapter.emit (events.js:198:13)
at slackEventAdapterMiddleware (C:\Users\VenkateshGujjala\Music\Chatbots_with_python\OS_installation\Slack\message\node_modules@slack\events-api\dist\express-middleware.js:160:20)
at Layer.handle [as handle_request] (C:\Users\VenkateshGujjala\Music\Chatbots_with_python\OS_installation\Slack\message\node_modules\express\lib\router\layer.js:95:5)
at trim_prefix (C:\Users\VenkateshGujjala\Music\Chatbots_with_python\OS_installation\Slack\message\node_modules\express\lib\router\index.js:317:13)
at C:\Users\VenkateshGujjala\Music\Chatbots_with_python\OS_installation\Slack\message\node_modules\express\lib\router\index.js:284:7
at Function.process_params (C:\Users\VenkateshGujjala\Music\Chatbots_with_python\OS_installation\Slack\message\node_modules\express\lib\router\index.js:335:12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.