From f5a32d8999d09482fac87452db25ada8ebce8941 Mon Sep 17 00:00:00 2001 From: Ashley Finafrock <35248895+Zerryth@users.noreply.github.com> Date: Tue, 25 Feb 2020 12:52:25 -0800 Subject: [PATCH] Added Channels enum in botbuilder-schema for ChannelIds constants (#1757) * Added Channels enum in botbuilder-schema for ChannelIds constants * removed commented out code * add botframework-schema as a bb-dialogs dependency, but hardcoded path, since new bits aren't published * Removed relative path; added reference to botframework-schema module directly in imports * changed path in package.json * Reduce import to only point to only botbuilder-core, as core rquires and exports schema * OAuthPrompt & OAuthPrompt tests now only reference bb-core, not schema directly --- .../botbuilder-dialogs/src/choices/channel.ts | 62 ++++++------------- .../src/prompts/oauthPrompt.ts | 11 ++-- .../tests/oauthPrompt.test.js | 13 ++-- libraries/botframework-schema/src/index.ts | 30 +++++++++ 4 files changed, 61 insertions(+), 55 deletions(-) diff --git a/libraries/botbuilder-dialogs/src/choices/channel.ts b/libraries/botbuilder-dialogs/src/choices/channel.ts index 3ded987acd..1b44614e2c 100644 --- a/libraries/botbuilder-dialogs/src/choices/channel.ts +++ b/libraries/botbuilder-dialogs/src/choices/channel.ts @@ -5,29 +5,7 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ -import { TurnContext } from 'botbuilder-core'; - -/** - * @private - */ -export const channels: any = { - console: 'console', - cortana: 'cortana', - directline: 'directline', - email: 'email', - emulator: 'emulator', - facebook: 'facebook', - groupme: 'groupme', - kik: 'kik', - line: 'line', - msteams: 'msteams', - skype: 'skype', - skypeforbusiness: 'skypeforbusiness', - slack: 'slack', - sms: 'sms', - telegram: 'telegram', - webchat: 'webchat' -}; +import { Channels, TurnContext } from 'botbuilder-core'; /** * @private @@ -36,18 +14,18 @@ export const channels: any = { */ export function supportsSuggestedActions(channelId: string, buttonCnt: number = 100): boolean { switch (channelId) { - case channels.facebook: - case channels.skype: + case Channels.Facebook: + case Channels.Skype: return (buttonCnt <= 10); - case channels.line: + case Channels.Line: return (buttonCnt <= 13); - case channels.kik: + case Channels.Kik: return (buttonCnt <= 20); - case channels.slack: - case channels.telegram: - case channels.emulator: - case channels.directline: - case channels.webchat: + case Channels.Slack: + case Channels.Telegram: + case Channels.Emulator: + case Channels.Directline: + case Channels.Webchat: return (buttonCnt <= 100); default: return false; @@ -61,17 +39,17 @@ export function supportsSuggestedActions(channelId: string, buttonCnt: number = */ export function supportsCardActions(channelId: string, buttonCnt: number = 100): boolean { switch (channelId) { - case channels.facebook: - case channels.skype: - case channels.msteams: + case Channels.Facebook: + case Channels.Skype: + case Channels.Msteams: return (buttonCnt <= 3); - case channels.line: + case Channels.Line: return (buttonCnt <= 99); - case channels.slack: - case channels.emulator: - case channels.directline: - case channels.webchat: - case channels.cortana: + case Channels.Slack: + case Channels.Emulator: + case Channels.Directline: + case Channels.Webchat: + case Channels.Cortana: return (buttonCnt <= 100); default: return false; @@ -84,7 +62,7 @@ export function supportsCardActions(channelId: string, buttonCnt: number = 100): */ export function hasMessageFeed(channelId: string): boolean { switch (channelId) { - case channels.cortana: + case Channels.Cortana: return false; default: return true; diff --git a/libraries/botbuilder-dialogs/src/prompts/oauthPrompt.ts b/libraries/botbuilder-dialogs/src/prompts/oauthPrompt.ts index a16a727a09..4d927a5fec 100644 --- a/libraries/botbuilder-dialogs/src/prompts/oauthPrompt.ts +++ b/libraries/botbuilder-dialogs/src/prompts/oauthPrompt.ts @@ -5,11 +5,10 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ -import { Activity, ActivityTypes, Attachment, CardFactory, InputHints, MessageFactory, OAuthLoginTimeoutKey, TokenResponse, TurnContext, IUserTokenProvider, OAuthCard, ActionTypes, } from 'botbuilder-core'; +import { Activity, ActivityTypes, Attachment, CardFactory, Channels, InputHints, MessageFactory, OAuthLoginTimeoutKey, TokenResponse, TurnContext, IUserTokenProvider, OAuthCard, ActionTypes, } from 'botbuilder-core'; import { Dialog, DialogTurnResult } from '../dialog'; import { DialogContext } from '../dialogContext'; import { PromptOptions, PromptRecognizerResult, PromptValidator } from './prompt'; -import { channels } from '../choices/channel'; import { isSkillClaim } from './skillsHelpers'; /** @@ -345,10 +344,10 @@ export class OAuthPrompt extends Dialog { private channelSupportsOAuthCard(channelId: string): boolean { switch (channelId) { - case channels.msteams: - case channels.cortana: - case channels.skype: - case channels.skypeforbusiness: + case Channels.Msteams: + case Channels.Cortana: + case Channels.Skype: + case Channels.Skypeforbusiness: return false; default: } diff --git a/libraries/botbuilder-dialogs/tests/oauthPrompt.test.js b/libraries/botbuilder-dialogs/tests/oauthPrompt.test.js index 5ec7b7a5f7..abac7ded9a 100644 --- a/libraries/botbuilder-dialogs/tests/oauthPrompt.test.js +++ b/libraries/botbuilder-dialogs/tests/oauthPrompt.test.js @@ -1,7 +1,6 @@ const assert = require('assert'); -const { ActionTypes, ActivityTypes, CardFactory, ConversationState, InputHints, MemoryStorage, TestAdapter, TurnContext } = require('botbuilder-core'); +const { ActionTypes, ActivityTypes, CardFactory, Channels, ConversationState, InputHints, MemoryStorage, TestAdapter, TurnContext } = require('botbuilder-core'); const { OAuthPrompt, DialogSet, DialogTurnStatus, ListStyle } = require('../'); -const { channels } = require('../lib/choices/channel'); const { AuthConstants } = require('../lib/prompts/skillsHelpers'); const beginMessage = { text: `begin`, type: 'message' }; @@ -301,7 +300,7 @@ describe('OAuthPrompt', function () { const fakeAdapter = {}; const context = new TurnContext(fakeAdapter, { activity: { - channelId: channels.webchat, + channelId: Channels.Webchat, serviceUrl: 'https://bing.com', } }); @@ -325,7 +324,7 @@ describe('OAuthPrompt', function () { }); const context = new TurnContext(adapter, { activity: { - channelId: channels.webchat, + channelId: Channels.Webchat, serviceUrl: 'https://bing.com', } }); @@ -361,7 +360,7 @@ describe('OAuthPrompt', function () { }); const context = new TurnContext(adapter, { activity: { - channelId: channels.webchat, + channelId: Channels.Webchat, serviceUrl: 'https://bing.com', } }); @@ -399,7 +398,7 @@ describe('OAuthPrompt', function () { text, title, }); const context = new TurnContext(adapter, { - channelId: channels.webchat, + channelId: Channels.Webchat, serviceUrl: 'wss://bing.com', }); // Override sendActivity @@ -434,7 +433,7 @@ describe('OAuthPrompt', function () { }); const context = new TurnContext(adapter, { activity: { - channelId: channels.webchat, + channelId: Channels.Webchat, serviceUrl: 'https://bing.com', } }); diff --git a/libraries/botframework-schema/src/index.ts b/libraries/botframework-schema/src/index.ts index d07b5d0f82..146f7192e6 100644 --- a/libraries/botframework-schema/src/index.ts +++ b/libraries/botframework-schema/src/index.ts @@ -1798,3 +1798,33 @@ export enum SemanticActionStateTypes { Done = 'done', } +/** + * Defines values for ChannelIds for Channels. + * Possible values include: 'console', 'cortana', 'directline', 'directlinespeech', 'email', + * 'emulator', 'facebook', 'groupme', 'kik', 'line', 'msteams', 'skype', 'skypeforbusiness', + * 'slack', 'sms', 'telegram', 'test', 'twilio-sms', 'webchat' + * @readonly + * @enum {string} + */ +export enum Channels { + Console = 'console', + Cortana = 'cortana', + Directline = 'directline', + DirectlineSpeech = 'directlinespeech', + Email = 'email', + Emulator = 'emulator', + Facebook = 'facebook', + Groupme = 'groupme', + Kik = 'kik', + Line = 'line', + Msteams = 'msteams', + Skype = 'skype', + Skypeforbusiness = 'skypeforbusiness', + Slack = 'slack', + Sms = 'sms', + Telegram = 'telegram', + Test = 'test', + Twilio = 'twilio-sms', + Webchat = 'webchat' +} +