Skip to content

Instantly share code, notes, and snippets.

@vidanov
Last active October 15, 2019 11:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vidanov/1d4e7eff8c3e186f1f6ae187f4b30c0d to your computer and use it in GitHub Desktop.
Save vidanov/1d4e7eff8c3e186f1f6ae187f4b30c0d to your computer and use it in GitHub Desktop.
const {App} = require('@slack/bolt');
const dotenv = require('dotenv').config();
// START APP
const app = new App({
token: process.env.TOKEN,
signingSecret: process.env.SIGNING_SECRET
});
app.use(pre); // PRE HOOKS FOR EVERY REQUEST
app.command('/modal', async ({
ack,
payload,
context
}) => {
// Acknowledge command request
ack();
var statusblocks = [{
"type": "section",
"block_id": "section-identifier",
"text": {
"type": "mrkdwn",
"text": "*Welcome* to ~my~ Block Kit _modal_!"
},
"accessory": {
"type": "button",
"text": {
"type": "plain_text",
"text": "Just a button",
},
"action_id": "button-identifier",
}
}];
try {
const result = await app.client.views.open({
token: context.botToken,
trigger_id: payload.trigger_id,
view: {
"type": "modal",
"callback_id": "ModalTest",
"title": {
"type": "plain_text",
"text": "dpa Status",
"emoji": true
},
"submit": {
"type": "plain_text",
"text": "Speichern",
"emoji": true
},
"close": {
"type": "plain_text",
"text": "Zurück",
"emoji": true
},
"blocks": statusblocks
}
});
} catch (error) {
console.error(error);
}
});
app.view('ModalTest', async ({
ack,
body,
view,
payload,
context
}) => {
console.log('> Modal saved button pushed')
// ack();
var statusblocks = [{
"type": "section",
"block_id": "section-identifier",
"text": {
"type": "mrkdwn",
"text": "Button saved pushed"
},
"accessory": {
"type": "button",
"text": {
"type": "plain_text",
"text": "Just a button",
},
"action_id": "button-identifier",
}
}];
try {
const result = await app.client.views.update({
token: context.botToken,
view_id: body.view.id,
response_action: "update",
view: {
"type": "modal",
"callback_id": "ModalTest",
"title": {
"type": "plain_text",
"text": "UPDATED MODAL",
"emoji": true
},
"submit": {
"type": "plain_text",
"text": "Speichern",
"emoji": true
},
"close": {
"type": "plain_text",
"text": "Zurück",
"emoji": true
},
"blocks": statusblocks
}
}
);
} catch (error) {
console.error(error);
}
})
function pre({
next
}) { // PREHOOK
// The current date output
var current_date = new Date().toISOString().
replace(/T/, ' '). // replace T with a space
replace(/\..+/, '') // delete the dot and everything after
console.log(current_date);
next();
}
// APP STARTER
(async () => {
await app.start(process.env.PORT || 3001);
console.log('⚡️ Bolt TEST app is running!');
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment