Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using interactive blocks with Slack Assistants #2384

Open
matined opened this issue Jan 7, 2025 · 2 comments
Open

Using interactive blocks with Slack Assistants #2384

matined opened this issue Jan 7, 2025 · 2 comments
Labels
question M-T: User needs support to use the project

Comments

@matined
Copy link

matined commented Jan 7, 2025

@slack/bolt version 4.2.0

My App and Receiver Configuration

const app = new App({
  token: process.env.SLACK_BOT_TOKEN,
  appToken: process.env.SLACK_APP_TOKEN,
  socketMode: true,
});

Question

Hi, is it possible to handle interactive blocks in Slack Assistant conversation?

My case is like that, I want to send a welcome message on assistant_thread_started with interactive text input block:

const assistant = new Assistant({
  threadStarted: async ({ say, saveThreadContext }) => {
    try {
      await say({
        text: "Hey there 👋",
        blocks: [
          {
            type: "input",
            element: {
              type: "url_text_input",
              action_id: "url_text_input",
              dispatch_action_config: {
                trigger_actions_on: ["on_enter_pressed"],
              },
            },
            label: {
              type: "plain_text",
              text: "Label",
              emoji: true,
            },
          },
        ],
      });

      await saveThreadContext();
    } catch (e) {
      console.error(e);
    }
  },
...
})

I see in the docs that I can create a separate action middleware like that:

app.action("url_text_input", async ({ action, ack, respond }) => {
  await ack();
  await respond("OK");
});

However, using this approach, I cannot use setStatus function. Is there any other way to handle interactive elements when using Slack Assistants?

@matined matined changed the title (Set a clear title describing your question) Using interactive blocks with Slack Assistants Jan 7, 2025
@zimeg zimeg added question M-T: User needs support to use the project and removed untriaged labels Jan 7, 2025
@zimeg
Copy link
Member

zimeg commented Jan 7, 2025

Hey @matined 👋 Thanks for sharing this setup 📚 ✨

I think the approach using dispatch_action_config and app.action is solid! I'm finding that setStatus can be called from the url_text_input handler using a few details from the body argument:

app.action('url_text_input', async ({ action, body, client, ack }) => {
  await ack();

  // https://api.slack.com/methods/assistant.threads.setTitle
  await client.assistant.threads.setTitle({
    channel_id: body.channel.id,
    title: 'chats about a link',
    thread_ts: body.message.thread_ts,
  });

  // https://api.slack.com/methods/assistant.threads.setStatus
  await client.assistant.threads.setStatus({
    channel_id: body.channel.id,
    status: 'surfing the web',
    thread_ts: body.message.thread_ts,
  });

  // https://api.slack.com/methods/chat.postMessage
  await client.chat.postMessage({
    channel: body.channel.id,
    text: `this link was shared: ${action.value}`,
    thread_ts: body.message.thread_ts,
  });
});

This does still use the action handler and requires more setup to call the API methods, but I'm wondering if it's an alright approach for the calls you're making?

Some unexpected behavior seems to happen when setting a status or posting a message before the user does - the suggested prompts remain present and the status text might not show. Wanted to share this here, but will report back with more findings on this! Setting a title and posting responses are all happening as expected too 👾

@matined
Copy link
Author

matined commented Jan 8, 2025

Thanks for the answer @zimeg 🙏 I've forgotten I can use client to do basically anything :))

I can confirm that setting status like that seems broken. There is a skeleton, but no status message:

image

Have you managed to find any workaround for setting the status properly? Working status messages are crucial for assistants.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question M-T: User needs support to use the project
Projects
None yet
Development

No branches or pull requests

2 participants