Skip to content

Commit 50e564a

Browse files
committed
Stop encoding text to generate unique dropdown identifier, use uuid instead
1 parent 92b4334 commit 50e564a

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

app/server.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,7 @@ app.event("message", async ({ event, client }) => {
5959
// Ignore everything except new messages
6060
return;
6161
}
62-
63-
const encodedText = btoa(event.text);
6462
console.log("Posting an ephemeral message to user:", event.user, "in channel:", event.channel);
65-
6663
try {
6764
// Respond with an ephemeral message containing a dropdown menu
6865
await client.chat.postEphemeral({
@@ -78,7 +75,7 @@ app.event("message", async ({ event, client }) => {
7875
},
7976
accessory: {
8077
type: "external_select",
81-
action_id: `category_select-${encodedText}`,
78+
action_id: `category_select-${event.ts}`,
8279
placeholder: {
8380
type: "plain_text",
8481
text: "Select a category",
@@ -137,12 +134,20 @@ app.action(/category_select-.*/, async ({ body, ack, say }) => {
137134
// Acknowledge the action
138135
await ack();
139136
console.log("body", body);
140-
const text = atob(body.actions[0].action_id.split("-")[1]);
137+
// const text = atob(body.actions[0].action_id.split("-")[1]); Currently not used since it caused bugs, so text is just an empty string
138+
const text = "";
141139
console.log("text", text);
142140
// Respond to the user's selection
143141
const selectedCategory = body.actions[0].selected_option.text.text;
144142
const dropdown_id = body.actions[0].action_id;
145-
addOrUpdateInc(body.user.username, text, selectedCategory, dropdown_id);
143+
try {
144+
addOrUpdateInc(body.user.username, text, selectedCategory, dropdown_id);
145+
await say(`You selected: ${selectedCategory}`);
146+
} catch (error) {
147+
say("There was an error adding the incident. Please try again later.");
148+
console.error("Error adding incident:", error);
149+
}
150+
146151
});
147152

148153

0 commit comments

Comments
 (0)