diff --git a/package.json b/package.json index 1b3d395..e55c209 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "slack-poll", - "version": "2.2.3", + "version": "2.2.4", "description": "Databaseless Slack Polling", "main": "server.js", "scripts": { diff --git a/src/Actions.ts b/src/Actions.ts index bcf8059..701ab7a 100644 --- a/src/Actions.ts +++ b/src/Actions.ts @@ -1,5 +1,5 @@ import { Poll } from "./Poll"; -import { WebClient, WebAPICallResult, ChatPostMessageArguments } from "@slack/web-api"; +import { ChatPostMessageArguments, ChatUpdateArguments, WebAPICallResult, WebClient } from "@slack/web-api"; import { KnownBlock } from "@slack/types"; import { Request, Response } from "express"; import * as Sentry from "@sentry/node"; @@ -109,7 +109,13 @@ export class Actions { await this.wc.chat.delete({ channel: payload.channel.id, ts: payload.message.ts }) .catch((err: any) => console.error(err)); // Must be artificially slowed down to prevent the poll from glitching out on Slack's end - setTimeout(() => this.postMessage(payload.channel.id, payload.message.text, payload.message.blocks), 300); + setTimeout(() => this.postMessage(payload.channel.id, "Poll Moved!", []).then((res: any) => { + const msg: ChatUpdateArguments = { + channel: payload.channel.id, text: payload.message.text, + ts: res.ts, blocks: payload.message.blocks + }; + this.wc.chat.update(msg); + }), 300); } else { this.postEphemeralOnlyAuthor("move", "poll", payload.channel.id, payload.user.id); } diff --git a/src/Poll.ts b/src/Poll.ts index b0c111f..a13b933 100644 --- a/src/Poll.ts +++ b/src/Poll.ts @@ -1,5 +1,5 @@ import { - KnownBlock, SectionBlock, ContextBlock, Button, ActionsBlock, StaticSelect, PlainTextElement, MrkdwnElement + ActionsBlock, Button, ContextBlock, KnownBlock, MrkdwnElement, PlainTextElement, SectionBlock, StaticSelect } from "@slack/types"; import { PollHelpers } from "./PollHelpers"; import * as Sentry from "@sentry/node"; @@ -81,7 +81,10 @@ export class Poll { } public getBlocks(): KnownBlock[] { - return this.message; + let str = JSON.stringify(this.message); + str = str.replace("<", "<") + .replace(">", ">").replace("&", "&"); + return JSON.parse(str); } public getAuthor(): string { @@ -182,7 +185,7 @@ export class Poll { } private generateVoteResults(): void { - // We throw out the old vote response and construct them again + // We throw out the old vote response and construct them again const sectionBlocks = this.generateResults(false); this.message = this.message.slice(0, this.getDividerId() + 1).concat(sectionBlocks); } diff --git a/src/PollHelpers.ts b/src/PollHelpers.ts index 00abd84..a5f0bc1 100644 --- a/src/PollHelpers.ts +++ b/src/PollHelpers.ts @@ -1,6 +1,4 @@ -import { - SectionBlock, ContextBlock, PlainTextElement, Option -} from "@slack/types"; +import { SectionBlock, ContextBlock, PlainTextElement, Option } from "@slack/types"; export class PollHelpers { public static appendIfMatching(optionArray: string[], keyword: string, appendText: string): string { @@ -22,4 +20,4 @@ export class PollHelpers { public static buildTextElem(text: string): PlainTextElement { return { type: "plain_text", text, emoji: true }; } -} \ No newline at end of file +}