-
Notifications
You must be signed in to change notification settings - Fork 479
/
Channel.cs
155 lines (136 loc) · 7.46 KB
/
Channel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
namespace Microsoft.Bot.Builder.Dialogs.Choices
{
/// <summary>
/// Methods for determining channel specific functionality.
/// </summary>
#pragma warning disable CA1052 // Static holder types should be Static or NotInheritable (we can't change this without breaking binary compat)
public class Channel
#pragma warning restore CA1052 // Static holder types should be Static or NotInheritable
{
/// <summary>
/// Determine if a number of Suggested Actions are supported by a Channel.
/// </summary>
/// <param name="channelId">The Channel to check the if Suggested Actions are supported in.</param>
/// <param name="buttonCnt">(Optional) The number of Suggested Actions to check for the Channel.</param>
/// <returns>True if the Channel supports the buttonCnt total Suggested Actions, False if the Channel does not support that number of Suggested Actions.</returns>
public static bool SupportsSuggestedActions(string channelId, int buttonCnt = 100)
{
return SupportsSuggestedActions(channelId, buttonCnt, null);
}
/// <summary>
/// Determine if a number of Suggested Actions are supported by a Channel.
/// </summary>
/// <param name="channelId">The Channel to check the if Suggested Actions are supported in.</param>
/// <param name="buttonCnt">(Optional) The number of Suggested Actions to check for the Channel.</param>
/// <param name="conversationType">(Optional) The type of the conversation.</param>
/// <returns>True if the Channel supports the buttonCnt total Suggested Actions, False if the Channel does not support that number of Suggested Actions.</returns>
public static bool SupportsSuggestedActions(string channelId, int buttonCnt = 100, string conversationType = default)
{
switch (channelId)
{
// https://developers.facebook.com/docs/messenger-platform/send-messages/quick-replies
case Connector.Channels.Facebook:
case Connector.Channels.Skype:
return buttonCnt <= 10;
// https://developers.line.biz/en/reference/messaging-api/#items-object
case Connector.Channels.Line:
return buttonCnt <= 13;
// https://dev.kik.com/#/docs/messaging#text-response-object
case Connector.Channels.Kik:
return buttonCnt <= 20;
case Connector.Channels.Telegram:
case Connector.Channels.Emulator:
case Connector.Channels.Directline:
case Connector.Channels.DirectlineSpeech:
case Connector.Channels.Webchat:
return buttonCnt <= 100;
// https://learn.microsoft.com/en-us/microsoftteams/platform/bots/how-to/conversations/conversation-messages?tabs=dotnet1%2Cdotnet2%2Cdotnet3%2Cdotnet4%2Cdotnet5%2Cdotnet#send-suggested-actions
case Connector.Channels.Msteams:
if (conversationType == "personal")
{
return buttonCnt <= 3;
}
return false;
default:
return false;
}
}
/// <summary>
/// Determine if a number of Card Actions are supported by a Channel.
/// </summary>
/// <param name="channelId">The Channel to check if the Card Actions are supported in.</param>
/// <param name="buttonCnt">(Optional) The number of Card Actions to check for the Channel.</param>
/// <returns>True if the Channel supports the buttonCnt total Card Actions, False if the Channel does not support that number of Card Actions.</returns>
public static bool SupportsCardActions(string channelId, int buttonCnt = 100)
{
switch (channelId)
{
case Connector.Channels.Facebook:
case Connector.Channels.Skype:
return buttonCnt <= 3;
case Connector.Channels.Msteams:
return buttonCnt <= 50;
case Connector.Channels.Line:
return buttonCnt <= 99;
case Connector.Channels.Slack:
case Connector.Channels.Telegram:
case Connector.Channels.Emulator:
case Connector.Channels.Directline:
case Connector.Channels.DirectlineSpeech:
case Connector.Channels.Webchat:
case Connector.Channels.Cortana:
return buttonCnt <= 100;
default:
return false;
}
}
/// <summary>
/// Determine if a Channel has a Message Feed.
/// </summary>
/// <param name="channelId">The Channel to check for Message Feed.</param>
/// <returns>True if the Channel has a Message Feed, False if it does not.</returns>
public static bool HasMessageFeed(string channelId)
{
switch (channelId)
{
case Connector.Channels.Cortana:
return false;
default:
return true;
}
}
/// <summary>
/// Maximum length allowed for Action Titles.
/// </summary>
/// <param name="channelId">The Channel to determine Maximum Action Title Length.</param>
/// <returns>The total number of characters allowed for an Action Title on a specific Channel.</returns>
#pragma warning disable CA1801 // Review unused parameters (we can't remove the channelId parameter without breaking binary compatibility)
public static int MaxActionTitleLength(string channelId) => 20;
#pragma warning restore CA1801 // Review unused parameters
/// <summary>
/// Get the Channel Id from the current Activity on the Turn Context.
/// </summary>
/// <param name="turnContext">The Turn Context to retrieve the Activity's Channel Id from.</param>
/// <returns>The Channel Id from the Turn Context's Activity.</returns>
public static string GetChannelId(ITurnContext turnContext) => string.IsNullOrEmpty(turnContext.Activity.ChannelId)
? string.Empty
: turnContext.Activity.ChannelId;
/// <summary>
/// Ids of the channels supported by the Bot Builder.
/// </summary>
// This class has been deprecated in favor of the class in Microsoft.Bot.Connector.Channels located
// at https://github.com/Microsoft/botbuilder-dotnet/libraries/Microsoft.Bot.Connector/Channels.cs.
// This change is non-breaking and this class now inherits from the class in the connector library.
[Obsolete("This class is deprecated. Please use Microsoft.Bot.Connector.Channels.")]
#pragma warning disable CA1034 // Nested types should not be visible (this type is deprecated, ignoring)
#pragma warning disable CA1724 // Namespace name conflict (this type is deprecated, ignoring)
public class Channels : Connector.Channels
#pragma warning restore CA1724 // Namespace name conflict
#pragma warning restore CA1034 // Nested types should not be visible
{
}
}
}