Skip to content

Commit

Permalink
Added Channels enum in botbuilder-schema for ChannelIds constants (#1757
Browse files Browse the repository at this point in the history
)

* 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
  • Loading branch information
Zerryth authored Feb 25, 2020
1 parent 3baf0e6 commit f5a32d8
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 55 deletions.
62 changes: 20 additions & 42 deletions libraries/botbuilder-dialogs/src/choices/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
11 changes: 5 additions & 6 deletions libraries/botbuilder-dialogs/src/prompts/oauthPrompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand Down Expand Up @@ -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:
}
Expand Down
13 changes: 6 additions & 7 deletions libraries/botbuilder-dialogs/tests/oauthPrompt.test.js
Original file line number Diff line number Diff line change
@@ -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' };
Expand Down Expand Up @@ -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',
}
});
Expand All @@ -325,7 +324,7 @@ describe('OAuthPrompt', function () {
});
const context = new TurnContext(adapter, {
activity: {
channelId: channels.webchat,
channelId: Channels.Webchat,
serviceUrl: 'https://bing.com',
}
});
Expand Down Expand Up @@ -361,7 +360,7 @@ describe('OAuthPrompt', function () {
});
const context = new TurnContext(adapter, {
activity: {
channelId: channels.webchat,
channelId: Channels.Webchat,
serviceUrl: 'https://bing.com',
}
});
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -434,7 +433,7 @@ describe('OAuthPrompt', function () {
});
const context = new TurnContext(adapter, {
activity: {
channelId: channels.webchat,
channelId: Channels.Webchat,
serviceUrl: 'https://bing.com',
}
});
Expand Down
30 changes: 30 additions & 0 deletions libraries/botframework-schema/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

0 comments on commit f5a32d8

Please sign in to comment.