如何使用 API 向消息中添加主题消息?

How can I add a message to a topic to a message by using the API?

我们有一个机器人通过 node-sdk (https://www.npmjs.com/package/circuit-sdk) 与 Circuit 连接。我们使用下面的代码

this.addEventListeners = function addEventListeners(client) {
    client.addEventListener('itemAdded', function (evt) {
            client.addTextItem(evt.item.convId, 'answer from bot');
    });
};

但是,该消息不会显示在当前主题下,而是作为对话中的单独消息显示。

我截图说明一下:

来自 circuit ui 的屏幕截图,带有示例对话框

如果我打开一个带有消息 ("Hi, this is the first message") 的新主题("Topic" 在我的屏幕截图中),机器人也会打开一个新主题并在其中回复我的消息 ("Answer from Bot (via Websocket)").怎么让它在我打开的话题里回复?

您需要在 addTextItem API 中传递线程的 ID (parentId)。参见 https://circuitsandbox.net/sdk/classes/Client.html#method_addTextItem

例如

client.addEventListener('itemAdded', function (evt) {
    client.addTextItem(evt.item.convId, {
        content: 'answer from bot',
        parentId: evt.item.itemId
    });
});