seratch / slack-edge

Slack app development framework for edge functions with streamlined TypeScript support
https://github.com/seratch/slack-edge-app-template
MIT License
87 stars 5 forks source link

context.say requires JSON.stringify for attachments to work #32

Closed matannahmani closed 2 months ago

matannahmani commented 2 months ago

Hi, I've been working with the context.say method while trying to attach attachments I realized you must stringify the comments for it to work, but the type says it needs to be in the shape of MessageAttachment[], can we adjust the client API to automatically stringify it to solve the problem? right now I have to ignore the TS check for the line to compile correctly I think the problem can be solved here if we add a simple check and stringify it automatically: https://github.com/seratch/slack-edge/blob/7dc09b1930a8d60d44ec237ae6a2c96a69f81795/src/app.ts#L826

before

          await client.chat.postMessage({
            channel: context.channelId,
            ...params,
          });

after

          await client.chat.postMessage({
            channel: context.channelId,
            ...params.attachments ? {attachments: JSON.stringify(params.attachments)} : {}
            ...params,
          });

where the problem occur:

slackApp.message("HELLO", async ({ context }) => {
 await context.say({
    text: "Test",
    attachments: JSON.stringify([
      {
        color: "#36a64f", // Replace with your desired color
        blocks: [
          {
            type: "header",
            text: {
              type: "plain_text",
              text: "Welcome to Lunchy AI Bot! 🥪",
              emoji: true,
            },
          },
          {
            type: "section",
            text: {
              type: "mrkdwn",
              text: "I’m here to help you plan your lunch meetings with colleagues.\n\n *Here’s what you can do:*",
            },
          },
          {
            type: "divider",
          },
          {
            type: "actions",
            elements: [
              {
                type: "button",
                action_id: "organize_lunch",
                text: {
                  type: "plain_text",
                  text: "Organize a Lunch",
                },
                value: "organize_lunch",
              },
              {
                type: "button",
                action_id: "find_restaurant",
                text: {
                  type: "plain_text",
                  text: "Find a Restaurant",
                },
                value: "find_restaurant",
              },
            ],
          },
        ],
      },
    ])
}
seratch commented 2 months ago

Hi @matannahmani, thanks for reporting this. I've confirmed that this is a bug that I recently caused. I will make a quick fix.

seratch commented 2 months ago

The latest version (0.13.2) resolves this issue. Please upgrade to the latest (slack-edge@latest). Thank you so much again for reporting this issue!