DirectLine API: Define a new ChannelId

Viewed 362

I'm implementing a new channel for my bot's front end using the botframework-directlinejs NodeJS SDK. This channel will provide some custom back-channel functionality; however, my bot needs to know that the conversation it is communicating with is via this channel before it can construct an activity to use it.

From what I can gather from the 'Activity' object in the API, the channelId field should be set by the channel.

However,

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)
);

indeed sends the message 'hi' to my bot, but the channelId comes out as 'directline'.

Performing this same operation in Fiddler as a post to https://directline.botframework.com/v3/directline/conversations/<conversationID>/activities has the same response.

My suspicion is that the 'channelId' property of the Activity object is read-only, and that the API adds this value.

Is it possible to set a custom id of the channel?

1 Answers

No, it is not possible to set a custom channel id. There is a corresponding connector service for each channel type. If you're using Direct Line, the channelId should be directline.

You can send custom information through channel data though:

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'));
Related