DirectLine API:定义新的ChannelId

问题描述 投票:2回答:1

我正在使用botframework-directlinejs NodeJS SDK为我的bot的前端实现一个新的通道。该频道将提供一些自定义的后台频道功能;但是,我的机器人需要知道它正在与之通信的对话是通过这个通道构建一个活动来使用它。

根据我从API中的'Activity' object收集的信息,channelId字段应该由频道设置。

然而,

myChannel.postActivity({
    type: 'message',
    text: 'hi',
    from: {
        id: "Node test user",
    },
    channelId: 'myChannel'
}).subscribe(
    id => console.log("Posted activity, assigned ID ", id),
    error => console.log("Error posting activity", error)
);

确实将消息'hi'发送到我的机器人,但channelId是'directline'。

在Fiddler中执行相同的操作作为https://directline.botframework.com/v3/directline/conversations/<conversationID>/activities的帖子具有相同的响应。

我怀疑Activity对象的'channelId'属性是只读的,并且API添加了这个值。

是否可以设置频道的自定义ID?

node.js botframework direct-line-botframework
1个回答
1
投票

不,无法设置自定义渠道ID。每种通道类型都有相应的连接器服务。如果您使用Direct Line,则channelId应为直线。

您可以通过频道数据发送自定义信息:

BotChat.App({
  botConnection: Object.assign({}, dl, {
     postActivity: activity => {
     var newActivity = Object.assign({}, activity, { channelData: { "MyKey": "MyValue" } });
     return dl.postActivity(newActivity);
    }
  }),
  bot: bot,
  user: user,
  resize: 'detect',
}, document.getElementById('bot'));
© www.soinside.com 2019 - 2024. All rights reserved.