|
|
@@ -1,6 +1,7 @@
|
|
|
const {
|
|
|
inputBlock, actionsBlock, buttonElement, checkboxesElementOption,
|
|
|
} = require('@growi/slack');
|
|
|
+const { fromUnixTime, format } = require('date-fns');
|
|
|
|
|
|
module.exports = () => {
|
|
|
const BaseSlackCommandHandler = require('./slack-command-handler');
|
|
|
@@ -8,46 +9,43 @@ module.exports = () => {
|
|
|
|
|
|
handler.handleCommand = async function(client, body, args, limit = 10) {
|
|
|
// TODO GW-6721 Get the time from args
|
|
|
- const reusult = await client.conversations.history({
|
|
|
+ const result = await client.conversations.history({
|
|
|
channel: body.channel_id,
|
|
|
limit,
|
|
|
});
|
|
|
- console.log(reusult);
|
|
|
- // Return Checkbox Message
|
|
|
+ // Return Checkbox Message
|
|
|
client.chat.postEphemeral({
|
|
|
channel: body.channel_id,
|
|
|
user: body.user_id,
|
|
|
text: 'Select messages to use.',
|
|
|
- blocks: this.togetterMessageBlocks(),
|
|
|
+ delete_original: true,
|
|
|
+ blocks: this.togetterMessageBlocks(result.messages),
|
|
|
});
|
|
|
return;
|
|
|
};
|
|
|
|
|
|
- handler.togetterMessageBlocks = function() {
|
|
|
+ handler.togetterMessageBlocks = function(messages) {
|
|
|
return [
|
|
|
- inputBlock(this.togetterCheckboxesElement(), 'selected_messages', 'Select massages to use.'),
|
|
|
+ inputBlock(this.togetterCheckboxesElement(messages), 'selected_messages', 'Select massages to use.'),
|
|
|
actionsBlock(buttonElement('Show more', 'togetterShowMore')),
|
|
|
inputBlock(this.togetterInputBlockElement('page_path', '/'), 'page_path', 'Page path'),
|
|
|
actionsBlock(buttonElement('Cancel', 'togetterCancelPageCreation'), buttonElement('Create page', 'togetterCreatePage', 'primary')),
|
|
|
];
|
|
|
};
|
|
|
|
|
|
- handler.togetterCheckboxesElement = function() {
|
|
|
+ handler.togetterCheckboxesElement = function(messages) {
|
|
|
return {
|
|
|
type: 'checkboxes',
|
|
|
- options: this.togetterCheckboxesElementOptions(),
|
|
|
+ options: this.togetterCheckboxesElementOptions(messages),
|
|
|
action_id: 'checkboxes_changed',
|
|
|
};
|
|
|
};
|
|
|
|
|
|
- handler.togetterCheckboxesElementOptions = function() {
|
|
|
- // increment options with results from conversations.history
|
|
|
- const options = [];
|
|
|
- // temporary code
|
|
|
- for (let i = 0; i < 10; i++) {
|
|
|
- const option = checkboxesElementOption('*username* 12:00PM', 'sample slack messages ... :star:', `selected-${i}`);
|
|
|
- options.push(option);
|
|
|
- }
|
|
|
+ handler.togetterCheckboxesElementOptions = function(messages) {
|
|
|
+ const options = messages.map((message, index) => {
|
|
|
+ const date = fromUnixTime(message.ts);
|
|
|
+ return checkboxesElementOption(`*${message.user}* ${format(new Date(date), 'yyyy/MM/dd HH:mm:ss')}`, message.text, `selected-${index}`);
|
|
|
+ });
|
|
|
return options;
|
|
|
};
|
|
|
|