Skip to content

Commit

Permalink
Update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Shane DeWael committed Mar 25, 2019
1 parent 8d92d8c commit 8d14167
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 900 deletions.
1 change: 0 additions & 1 deletion examples/.nvmrc

This file was deleted.

13 changes: 0 additions & 13 deletions examples/README.md

This file was deleted.

28 changes: 0 additions & 28 deletions examples/basic-incoming-webhook.js

This file was deleted.

41 changes: 0 additions & 41 deletions examples/basic-rtm-client.js

This file was deleted.

28 changes: 0 additions & 28 deletions examples/basic-web-client.js

This file was deleted.

4 changes: 2 additions & 2 deletions examples/express-all-interactions/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "express-all-interactions",
"name": "@slack/express-all-interactions",
"private": true,
"version": "1.0.0",
"description": "An example of using Slack Interactive Messages for Node",
Expand All @@ -11,7 +11,7 @@
"author": "Ankur Oberoi <aoberoi@gmail.com>",
"license": "MIT",
"dependencies": {
"@slack/client": "^4.1.0",
"@slack/web-api": "^5.0.0",
"@slack/interactive-messages": "*",
"axios": "^0.18.0",
"body-parser": "^1.18.2",
Expand Down
23 changes: 14 additions & 9 deletions examples/express-all-interactions/server.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const http = require('http');
const express = require('express');
const { createMessageAdapter } = require('@slack/interactive-messages');
const { WebClient } = require('@slack/client');
const { WebClient } = require('@slack/web-api');
const { users, neighborhoods } = require('./models');
const axios = require('axios');
const bodyParser = require('body-parser');
Expand Down Expand Up @@ -223,14 +223,19 @@ function slackSlashCommand(req, res, next) {
res.json(interactiveMenu);
} else if (type === 'dialog') {
res.send();
web.dialog.open({
trigger_id: req.body.trigger_id,
dialog,
}).catch((error) => {
return axios.post(req.body.response_url, {
text: `An error occurred while opening the dialog: ${error.message}`,
});
}).catch(console.error);
(async () => {
try {
// Open dialog
const response = await web.dialog.open({
trigger_id: req.body.trigger_id,
dialog,
});
} catch (error) {
axios.post(req.body.response_url, {
text: `An error occurred while opening the dialog: ${error.message}`,
}).catch(console.error);
}
})();
} else {
res.send('Use this command followed by `button`, `menu`, or `dialog`.');
}
Expand Down
31 changes: 22 additions & 9 deletions examples/greet-and-react/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// Load environment variables from `.env` file (optional)
require('dotenv').config();

const slackEventsApi = require('@slack/events-api');
const SlackClient = require('@slack/client').WebClient;
const { createEventAdapter } = require('@slack/events-api');
const { WebClient } = require('@slack/web-api');
const passport = require('passport');
const LocalStorage = require('node-localstorage').LocalStorage;
const SlackStrategy = require('@aoberoi/passport-slack').default.Strategy;
const http = require('http');
const express = require('express');

// *** Initialize event adapter using signing secret from environment variables ***
const slackEvents = slackEventsApi.createEventAdapter(process.env.SLACK_SIGNING_SECRET, {
const slackEvents = createEventAdapter(process.env.SLACK_SIGNING_SECRET, {
includeBody: true
});

Expand All @@ -25,7 +25,7 @@ const botAuthorizationStorage = new LocalStorage('./storage');
const clients = {};
function getClientByTeamId(teamId) {
if (!clients[teamId] && botAuthorizationStorage.getItem(teamId)) {
clients[teamId] = new SlackClient(botAuthorizationStorage.getItem(teamId));
clients[teamId] = new WebClient(botAuthorizationStorage.getItem(teamId));
}
if (clients[teamId]) {
return clients[teamId];
Expand Down Expand Up @@ -79,9 +79,15 @@ slackEvents.on('message', (message, body) => {
if (!slack) {
return console.error('No authorization found for this team. Did you install the app through the url provided by ngrok?');
}
// Respond to the message back in the same channel
slack.chat.postMessage({ channel: message.channel, text: `Hello <@${message.user}>! :tada:` })
.catch(console.error);

(async () => {
try {
// Respond to the message back in the same channel
const response = await slack.chat.postMessage({ channel: message.channel, text: `Hello <@${message.user}>! :tada:` });
} catch (error) {
console.log(error.data);
}
})();
}
});

Expand All @@ -94,8 +100,15 @@ slackEvents.on('reaction_added', (event, body) => {
return console.error('No authorization found for this team. Did you install the app through the url provided by ngrok?');
}
// Respond to the reaction back with the same emoji
slack.chat.postMessage({ channel: event.item.channel, text: `:${event.reaction}:` })
.catch(console.error);

(async () => {
try {
// Respond to the message back in the same channel
const response = await slack.chat.postMessage({ channel: event.item.channel, text: `:${event.reaction}:` });
} catch (error) {
console.log(error.data);
}
})();
});

// *** Handle errors ***
Expand Down
2 changes: 1 addition & 1 deletion examples/greet-and-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"license": "MIT",
"dependencies": {
"@aoberoi/passport-slack": "^1.0.5",
"@slack/client": "^4.3.1",
"@slack/web-api": "^5.0.0",
"@slack/events-api": "^2.0.0",
"dotenv": "^4.0.0",
"express": "^4.16.3",
Expand Down
52 changes: 0 additions & 52 deletions examples/incoming-webhook-with-proxy.js

This file was deleted.

Loading

0 comments on commit 8d14167

Please sign in to comment.