Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

botframeworkv4 - List of available Channel IDs

While exploring the new preview of the botframeworkv4 in C#, I came across a case where I need to do a specific action for a certain channel. In botframeworkv3, I used to access all the channels string names using ChannelIds but I can't find it here.

I know that I can directly write "facebook" for example, but using the provided list prevents any typos and improves readability.

Therefore, what is the equivalent of ChannelIds in botframeworkv4?

like image 903
Ziad Akiki Avatar asked Sep 12 '18 08:09

Ziad Akiki


2 Answers

2019-2020 Response:

The Channel list is available in Channels object in Microsoft.Bot.Connector namespace:

https://github.com/microsoft/botbuilder-dotnet/blob/master/libraries/Microsoft.Bot.Connector/Channels.cs

2018 Response:

ChannelId is still an existing property in Activity object in v4, see sources:

https://github.com/Microsoft/botbuilder-dotnet/blob/master/libraries/Microsoft.Bot.Schema/IActivity.cs

/// <summary>
/// Channel this activity is associated with
/// </summary>
string ChannelId { get; set; }

The list of channelId values is still available in v4 through Microsoft.Bot.Builder.Classic:

https://github.com/Microsoft/botbuilder-dotnet/blob/master/libraries/Microsoft.Bot.Builder.Classic/Microsoft.Bot.Builder.Classic/ConnectorEx/IChannelCapability.cs

public sealed class ChannelIds
{
    public const string Facebook = "facebook";
    public const string Skype = "skype";
    public const string Msteams = "msteams";
    public const string Telegram = "telegram";
    public const string Kik = "kik";
    public const string Email = "email";
    public const string Slack = "slack";
    public const string Groupme = "groupme";
    public const string Sms = "sms";
    public const string Emulator = "emulator";
    public const string Directline = "directline";
    public const string Webchat = "webchat";
    public const string Console = "console";
    public const string Cortana = "cortana";
}

Side note: you can simply add your own list:

public enum ChannelEnum
{
    emulator,
    facebook,
    skype,
    webchat,
    directline
    // ...
}

and use activity.ChannelId == ChannelEnum.webchat.ToString()

like image 168
Nicolas R Avatar answered Sep 26 '22 00:09

Nicolas R


ChannelIds has been replaced with Channels in the C# V4 SDK and is available under Microsoft.Bot.Connector.

Checking for a specific channel can be done easily, for example:

var isEmail = turnContext.Activity.ChannelId == Channels.Email;

Use Nicholas R's answer if you need to add custom channels (or example Android, iOS) to the list.

like image 33
Ziad Akiki Avatar answered Sep 25 '22 00:09

Ziad Akiki