-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Piping slack requests to another port works!
- Loading branch information
1 parent
3afa20e
commit fd94669
Showing
6 changed files
with
117 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { SlashCommand, AckFn, RespondArguments, RespondFn, App, Installation } from "@slack/bolt"; | ||
import SlackCommands from "./SlackCommands"; | ||
import { Collections, getDatabase } from "./MongoDB"; | ||
|
||
const slackApp = new App({ | ||
// token: process.env.SLACK_BOT_TOKEN, | ||
signingSecret: process.env.SLACK_SIGNING_SECRET, | ||
socketMode: true, | ||
port: +process.env.SLACK_PORT, | ||
redirectUri: "https://localhost/slack/oauth_redirect", | ||
installerOptions: { | ||
redirectUriPath: "/slack/oauth_redirect", | ||
}, | ||
appToken: process.env.SLACK_APP_TOKEN, | ||
clientId: process.env.NEXT_PUBLIC_SLACK_CLIENT_ID, | ||
clientSecret: process.env.SLACK_CLIENT_SECRET, | ||
stateSecret: process.env.SLACK_STATE_SECRET, | ||
scopes: ["chat:write", "commands"], | ||
installationStore: { | ||
storeInstallation: async (installation) => { | ||
console.log("Storing installation", installation.team?.name); | ||
|
||
const db = await getDatabase(); | ||
|
||
db.addObject(Collections.SlackInstallations, installation); | ||
}, | ||
fetchInstallation: async (InstallQuery) => { | ||
const db = await getDatabase(); | ||
|
||
console.log("Fetching installation: " + InstallQuery.teamId); | ||
const installation = await db.findObject<Installation>(Collections.SlackInstallations, { | ||
userId: InstallQuery.userId, | ||
team: { | ||
id: InstallQuery.teamId, | ||
} | ||
}); | ||
|
||
console.log("Found installation", installation.team?.name); | ||
|
||
if (!installation) { | ||
throw new Error("No installation found"); | ||
} | ||
|
||
return installation; | ||
}, | ||
}, | ||
}); | ||
|
||
slackApp.command(/\/.*/, async (props: { command: SlashCommand, ack: AckFn<string | RespondArguments>, respond: RespondFn }) => { | ||
const { command, ack, respond } = props; | ||
|
||
const commandName = command.command.replace("/", ""); | ||
const handler = SlackCommands[commandName]; | ||
|
||
if (handler) { | ||
handler(command, ack, respond); | ||
} | ||
else { | ||
await ack(); | ||
await respond(`Command not found: ` + commandName); | ||
} | ||
}); | ||
|
||
export async function startSlackApp() { | ||
await slackApp.start(process.env.SLACK_PORT); | ||
console.log("Slack bot is listening at: http://localhost:" + process.env.SLACK_PORT); | ||
|
||
return slackApp; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters