|
|
@@ -1,14 +1,11 @@
|
|
|
|
|
|
const express = require('express');
|
|
|
-const { createMessageAdapter } = require('@slack/interactive-messages');
|
|
|
|
|
|
const router = express.Router();
|
|
|
|
|
|
module.exports = (crowi) => {
|
|
|
this.app = crowi.express;
|
|
|
|
|
|
- const signingSecret = crowi.configManager.getConfig('crowi', 'slackbot:signingSecret');
|
|
|
- const slackInteractions = createMessageAdapter(signingSecret);
|
|
|
|
|
|
// Check if the access token is correct
|
|
|
// function verificationAccessToken(req, res, next) {
|
|
|
@@ -22,12 +19,6 @@ module.exports = (crowi) => {
|
|
|
// return next();
|
|
|
// }
|
|
|
|
|
|
- slackInteractions.viewSubmission('view_submission', (payload) => {
|
|
|
- // Log the input elements from the view submission.
|
|
|
- console.log(payload.view.state);
|
|
|
- });
|
|
|
-
|
|
|
-
|
|
|
function verificationRequestUrl(req, res, next) {
|
|
|
// for verification request URL on Event Subscriptions
|
|
|
if (req.body.type === 'url_verification') {
|
|
|
@@ -62,19 +53,44 @@ module.exports = (crowi) => {
|
|
|
|
|
|
});
|
|
|
|
|
|
+ const handleBlockActions = async(payload) => {
|
|
|
+ const { action_id: actionId } = payload.actions[0];
|
|
|
+
|
|
|
+ switch (actionId) {
|
|
|
+ case 'shareSearchResults': {
|
|
|
+ console.log(payload);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case 'showNextResults': {
|
|
|
+ const parsedValue = JSON.parse(payload.actions[0].value);
|
|
|
+
|
|
|
+ const { body, args, offset } = parsedValue;
|
|
|
+ const newOffset = offset + 10;
|
|
|
+ await crowi.boltService.showEphemeralSearchResults(body, args, newOffset);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
router.post('/interactive', verificationRequestUrl, async(req, res) => {
|
|
|
|
|
|
// Send response immediately to avoid opelation_timeout error
|
|
|
// See https://api.slack.com/apis/connections/events-api#the-events-api__responding-to-events
|
|
|
res.send();
|
|
|
- console.log(req.body);
|
|
|
+
|
|
|
const payload = JSON.parse(req.body.payload);
|
|
|
const { type } = payload;
|
|
|
+ // const { callback_id: callbackId } = payload.view;
|
|
|
|
|
|
switch (type) {
|
|
|
- case 'view_submission':
|
|
|
- await crowi.boltService.createPageInGrowi(payload);
|
|
|
+ case 'block_actions':
|
|
|
+ handleBlockActions(payload);
|
|
|
break;
|
|
|
+ // case 'block_actions':
|
|
|
+ // await crowi.boltService.createPageInGrowi(payload);
|
|
|
+ // break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|