You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Circuit Bot被添加至Circuit对话时触发指定事件?

How to Trigger Self-Introduction and Form Collection When Circuit Bot is Added to a Conversation

Great question! Setting up your Circuit Bot to auto-introduce itself and send a form when added to a conversation is straightforward with Circuit's Bot Framework. Let's walk through the exact steps:

1. Listen for the Bot Addition Event

First, your bot needs to detect when it's been added to a new conversation. Circuit's SDK emits a memberAdded event whenever a new member joins a conversation—we just need to check if that new member is the bot itself.

Here's a JavaScript example using the Circuit SDK:

const Circuit = require('circuit-sdk');

// Initialize your bot client with credentials from the Circuit Developer Portal
const botClient = new Circuit.Client({
  client_id: 'YOUR_BOT_CLIENT_ID',
  client_secret: 'YOUR_BOT_CLIENT_SECRET'
});

// Listen for new members joining conversations
botClient.addEventListener('memberAdded', async (event) => {
  // Verify the added member is this bot
  if (event.member.userId === botClient.loggedOnUser.userId) {
    // Kick off our welcome workflow
    await handleBotAddedToConversation(event.convId);
  }
});

2. Send the Self-Introduction Message

Once we confirm the bot was added, we can send a friendly intro message using the addTextItem API. We'll wrap this in a helper function to keep things clean:

async function handleBotAddedToConversation(convId) {
  // Send the introduction message
  const introText = "Hey there! I'm your Circuit Bot. I’m here to help you gather and organize key details. Let’s start by filling out this quick form!";
  await botClient.addTextItem(convId, introText);

  // Next, send the information collection form
  await sendInformationForm(convId);
}

3. Create and Send the Circuit Form

Circuit lets you build structured forms using the addFormItem API. You can customize fields (text inputs, email fields, dropdowns, etc.) based on the info you need to collect. Here's an example:

async function sendInformationForm(convId) {
  // Define your form structure
  const collectionForm = {
    title: 'Team Member Information Form',
    fields: [
      {
        type: 'text',
        label: 'Full Name',
        name: 'fullName',
        required: true // Mark field as mandatory
      },
      {
        type: 'email',
        label: 'Work Email',
        name: 'workEmail',
        required: true
      },
      {
        type: 'select',
        label: 'Department',
        name: 'department',
        options: ['Engineering', 'Marketing', 'Sales', 'HR', 'Operations'],
        required: true
      },
      {
        type: 'textarea',
        label: 'Brief About Yourself',
        name: 'bio',
        required: false // Optional field
      }
    ]
  };

  // Send the form to the conversation
  await botClient.addFormItem(convId, collectionForm);
}

Quick Notes to Keep in Mind

  • Permissions: Ensure your bot has the sendMessages and manageForms permissions enabled in the Circuit Developer Portal—without these, the bot won't be able to send messages or forms.
  • Testing: Always test the workflow by adding the bot to a test conversation first to verify the event triggers and messages/forms send correctly.
  • Customization: Tweak the intro text and form fields to match your specific use case (e.g., add date pickers, checkboxes, etc.).

内容的提问来源于stack exchange,提问作者Kamal Garg

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 07:58:20