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

Fix #1243 Socket Mode reconnection issue #1465

Merged
merged 6 commits into from Apr 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/socket-mode/.gitignore
@@ -1,6 +1,6 @@
# node / npm stuff
/node_modules
/package-lock.json
node_modules
package-lock.json

# build products
/dist
Expand Down
12 changes: 12 additions & 0 deletions packages/socket-mode/examples/link.sh
@@ -0,0 +1,12 @@
#!/bin/bash

current_dir=`dirname $0`
cd ${current_dir}
npm unlink @slack/socket-mode \
&& npm i \
&& cd .. \
&& npm link \
&& cd - \
&& npm i \
&& npm link @slack/socket-mode

17 changes: 17 additions & 0 deletions packages/socket-mode/examples/package.json
@@ -0,0 +1,17 @@
{
"name": "examples",
"version": "1.0.0",
"description": "",
"main": "simple.js",
"scripts": {
"start": "nodemon simple.js"
},
"author": "Slack Technologies, LLC",
"license": "MIT",
"devDependencies": {
"nodemon": "^2.0.15"
},
"dependencies": {
"https-proxy-agent": "^5.0.0"
}
}
23 changes: 23 additions & 0 deletions packages/socket-mode/examples/proxy.js
@@ -0,0 +1,23 @@
const { SocketModeClient, LogLevel } = require("@slack/socket-mode");
const { WebClient } = require("@slack/web-api");
const HttpsProxyAgent = require("https-proxy-agent");
const clientOptions = { agent: new HttpsProxyAgent("http://localhost:9001") };

const socketModeClient = new SocketModeClient({
appToken: process.env.SLACK_APP_TOKEN,
logLevel: LogLevel.DEBUG,
clientOptions,
});
const webClient = new WebClient(process.env.SLACK_BOT_TOKEN, {
logLevel: LogLevel.DEBUG,
clientOptions,
});

socketModeClient.on("slack_event", async ({ ack, body }) => {
console.log(body);
await ack();
});

(async () => {
await socketModeClient.start();
})();
29 changes: 29 additions & 0 deletions packages/socket-mode/examples/simple.js
@@ -0,0 +1,29 @@
const { SocketModeClient, LogLevel } = require("@slack/socket-mode");
const { WebClient } = require("@slack/web-api");

const logLevel = LogLevel.INFO;
const socketModeClient = new SocketModeClient({
appToken: process.env.SLACK_APP_TOKEN,
logLevel,
// pingPongLoggingEnabled: true,
// serverPingTimeout: 30000,
// clientPingTimeout: 5000,
});
const webClient = new WebClient(process.env.SLACK_BOT_TOKEN, {
logLevel,
});

socketModeClient.on("slack_event", async ({ ack, body }) => {
try {
console.log(body);
// setTimeout(() => { ack(); }, 2000);
await ack();
} catch (e) {
console.error(e);
}
});

(async () => {
// Connect to Slack
await socketModeClient.start();
})();