From 4b07207c480e216e3741b5c3af44e4ed056e68ec Mon Sep 17 00:00:00 2001 From: Ben Brown Date: Mon, 7 Jan 2019 11:58:55 -0600 Subject: [PATCH 1/7] Add support for tenant field in conversation references and in createConversation (required for MS Teams) --- libraries/botbuilder-core/src/turnContext.ts | 3 ++- libraries/botbuilder/src/botFrameworkAdapter.ts | 5 +++++ libraries/botframework-schema/src/index.ts | 6 ++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/libraries/botbuilder-core/src/turnContext.ts b/libraries/botbuilder-core/src/turnContext.ts index eeb4a747d1..0747a0f1cf 100644 --- a/libraries/botbuilder-core/src/turnContext.ts +++ b/libraries/botbuilder-core/src/turnContext.ts @@ -98,7 +98,8 @@ export class TurnContext { bot: shallowCopy(activity.recipient), conversation: shallowCopy(activity.conversation), channelId: activity.channelId, - serviceUrl: activity.serviceUrl + serviceUrl: activity.serviceUrl, + channelData: activity.channelData }; } diff --git a/libraries/botbuilder/src/botFrameworkAdapter.ts b/libraries/botbuilder/src/botFrameworkAdapter.ts index fc3e57e27e..7672c8671a 100644 --- a/libraries/botbuilder/src/botFrameworkAdapter.ts +++ b/libraries/botbuilder/src/botFrameworkAdapter.ts @@ -230,6 +230,11 @@ export class BotFrameworkAdapter extends BotAdapter { const client: ConnectorClient = this.createConnectorClient(reference.serviceUrl); const response = await client.conversations.createConversation(parameters); + // Mix in the tenant ID if specified. This is required for MS Teams. + if (reference.channelData && reference.channelData.tenant) { + parameters.channelData = { tenant: reference.channelData.tenant }; + } + // Initialize request and copy over new conversation ID and updated serviceUrl. const request: Partial = TurnContext.applyConversationReference( { type: 'event', name: 'createConversation' }, diff --git a/libraries/botframework-schema/src/index.ts b/libraries/botframework-schema/src/index.ts index e5f66d8605..c2fcc1857a 100644 --- a/libraries/botframework-schema/src/index.ts +++ b/libraries/botframework-schema/src/index.ts @@ -316,6 +316,12 @@ export interface ConversationReference { * the referenced conversation may be performed */ serviceUrl: string; + + /** + * @member {any} [channelData] Channel specific payload for re-creating the + * conversation + */ + channelData?: any; } /** From ca6066c483e2a25266e2b09fb6d7ff9e71d9b7b3 Mon Sep 17 00:00:00 2001 From: Ben Brown Date: Thu, 31 Jan 2019 08:59:04 -0800 Subject: [PATCH 2/7] fix issue with code order --- libraries/botbuilder/src/botFrameworkAdapter.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries/botbuilder/src/botFrameworkAdapter.ts b/libraries/botbuilder/src/botFrameworkAdapter.ts index 7672c8671a..0e174e16de 100644 --- a/libraries/botbuilder/src/botFrameworkAdapter.ts +++ b/libraries/botbuilder/src/botFrameworkAdapter.ts @@ -228,13 +228,14 @@ export class BotFrameworkAdapter extends BotAdapter { // Create conversation const parameters: ConversationParameters = { bot: reference.bot, members: [reference.user] } as ConversationParameters; const client: ConnectorClient = this.createConnectorClient(reference.serviceUrl); - const response = await client.conversations.createConversation(parameters); // Mix in the tenant ID if specified. This is required for MS Teams. if (reference.channelData && reference.channelData.tenant) { parameters.channelData = { tenant: reference.channelData.tenant }; } + const response = await client.conversations.createConversation(parameters); + // Initialize request and copy over new conversation ID and updated serviceUrl. const request: Partial = TurnContext.applyConversationReference( { type: 'event', name: 'createConversation' }, From 8e552440aa78154dfac9fac9ca44607dfc56847f Mon Sep 17 00:00:00 2001 From: Ben Brown Date: Thu, 31 Jan 2019 09:42:42 -0800 Subject: [PATCH 3/7] temporary changes --- libraries/botbuilder-core/src/turnContext.ts | 15 +++++++++++++++ libraries/botbuilder/src/botFrameworkAdapter.ts | 5 +++++ 2 files changed, 20 insertions(+) diff --git a/libraries/botbuilder-core/src/turnContext.ts b/libraries/botbuilder-core/src/turnContext.ts index 0747a0f1cf..b0dc51ec4c 100644 --- a/libraries/botbuilder-core/src/turnContext.ts +++ b/libraries/botbuilder-core/src/turnContext.ts @@ -101,6 +101,21 @@ export class TurnContext { serviceUrl: activity.serviceUrl, channelData: activity.channelData }; + + // possible better solution? + // const reference = { + // activityId: activity.id, + // user: shallowCopy(activity.from), + // bot: shallowCopy(activity.recipient), + // conversation: shallowCopy(activity.conversation), + // channelId: activity.channelId, + // serviceUrl: activity.serviceUrl, + // }; + // if (activity.channelData.tenant) { + // reference.conversation.tenant = activity.channelData.tenant; + // } + // return reference; + } } /** diff --git a/libraries/botbuilder/src/botFrameworkAdapter.ts b/libraries/botbuilder/src/botFrameworkAdapter.ts index 0e174e16de..8bb51f0001 100644 --- a/libraries/botbuilder/src/botFrameworkAdapter.ts +++ b/libraries/botbuilder/src/botFrameworkAdapter.ts @@ -234,6 +234,11 @@ export class BotFrameworkAdapter extends BotAdapter { parameters.channelData = { tenant: reference.channelData.tenant }; } + // possible better solution? Missing def of tenant on this element! + // if (reference.conversation && reference.conversation.tenant) { + // parameters.channelData = { tenant: reference.conversation.tenant }; + // } + const response = await client.conversations.createConversation(parameters); // Initialize request and copy over new conversation ID and updated serviceUrl. From 3c19d2591d2b715c1d34d421590d17ef8ba614ab Mon Sep 17 00:00:00 2001 From: Ben Brown Date: Wed, 6 Feb 2019 10:16:26 -0600 Subject: [PATCH 4/7] Adjust approach to adding tenantId to createConversation API call --- libraries/botbuilder-core/src/turnContext.ts | 18 +----------------- .../botbuilder/src/botFrameworkAdapter.ts | 9 ++------- libraries/botframework-schema/src/index.ts | 6 ------ 3 files changed, 3 insertions(+), 30 deletions(-) diff --git a/libraries/botbuilder-core/src/turnContext.ts b/libraries/botbuilder-core/src/turnContext.ts index b0dc51ec4c..eeb4a747d1 100644 --- a/libraries/botbuilder-core/src/turnContext.ts +++ b/libraries/botbuilder-core/src/turnContext.ts @@ -98,24 +98,8 @@ export class TurnContext { bot: shallowCopy(activity.recipient), conversation: shallowCopy(activity.conversation), channelId: activity.channelId, - serviceUrl: activity.serviceUrl, - channelData: activity.channelData + serviceUrl: activity.serviceUrl }; - - // possible better solution? - // const reference = { - // activityId: activity.id, - // user: shallowCopy(activity.from), - // bot: shallowCopy(activity.recipient), - // conversation: shallowCopy(activity.conversation), - // channelId: activity.channelId, - // serviceUrl: activity.serviceUrl, - // }; - // if (activity.channelData.tenant) { - // reference.conversation.tenant = activity.channelData.tenant; - // } - // return reference; - } } /** diff --git a/libraries/botbuilder/src/botFrameworkAdapter.ts b/libraries/botbuilder/src/botFrameworkAdapter.ts index d1778fa67f..e72e810a6c 100644 --- a/libraries/botbuilder/src/botFrameworkAdapter.ts +++ b/libraries/botbuilder/src/botFrameworkAdapter.ts @@ -230,15 +230,10 @@ export class BotFrameworkAdapter extends BotAdapter { const client: ConnectorClient = this.createConnectorClient(reference.serviceUrl); // Mix in the tenant ID if specified. This is required for MS Teams. - if (reference.channelData && reference.channelData.tenant) { - parameters.channelData = { tenant: reference.channelData.tenant }; + if (reference.conversation && reference.conversation.tenantId) { + parameters.channelData = { tenant: { id: reference.conversation.tenantId } }; } - // possible better solution? Missing def of tenant on this element! - // if (reference.conversation && reference.conversation.tenant) { - // parameters.channelData = { tenant: reference.conversation.tenant }; - // } - const response = await client.conversations.createConversation(parameters); // Initialize request and copy over new conversation ID and updated serviceUrl. diff --git a/libraries/botframework-schema/src/index.ts b/libraries/botframework-schema/src/index.ts index e1429fb193..8fafe66f4c 100644 --- a/libraries/botframework-schema/src/index.ts +++ b/libraries/botframework-schema/src/index.ts @@ -262,12 +262,6 @@ export interface ConversationReference { * Service endpoint where operations concerning the referenced conversation may be performed */ serviceUrl: string; - - /** - * @member {any} [channelData] Channel specific payload for re-creating the - * conversation - */ - channelData?: any; } /** From 2b2c7c025b8cebafa3ac5302008fc683bb3684bb Mon Sep 17 00:00:00 2001 From: Ben Brown Date: Wed, 6 Feb 2019 10:24:27 -0600 Subject: [PATCH 5/7] update to reflect temporary and long term solution --- libraries/botbuilder/src/botFrameworkAdapter.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libraries/botbuilder/src/botFrameworkAdapter.ts b/libraries/botbuilder/src/botFrameworkAdapter.ts index e72e810a6c..6b9dacb519 100644 --- a/libraries/botbuilder/src/botFrameworkAdapter.ts +++ b/libraries/botbuilder/src/botFrameworkAdapter.ts @@ -231,7 +231,12 @@ export class BotFrameworkAdapter extends BotAdapter { // Mix in the tenant ID if specified. This is required for MS Teams. if (reference.conversation && reference.conversation.tenantId) { + // Putting tenantId in channelData is a temporary solution while we wait for the Teams API to be updated parameters.channelData = { tenant: { id: reference.conversation.tenantId } }; + + // Permanent solution is to put tenantId in conversation.tenantId + parameters.conversation = { tenantId: reference.conversation.tenantId }; + } const response = await client.conversations.createConversation(parameters); From 03a0373df59d7d5512a19b624fbbff2eb029c160 Mon Sep 17 00:00:00 2001 From: Ben Brown Date: Fri, 8 Feb 2019 15:22:01 -0600 Subject: [PATCH 6/7] make schema adjustments to match protocol --- libraries/botbuilder/src/botFrameworkAdapter.ts | 2 +- libraries/botframework-schema/src/index.ts | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/libraries/botbuilder/src/botFrameworkAdapter.ts b/libraries/botbuilder/src/botFrameworkAdapter.ts index 6b9dacb519..cf91907137 100644 --- a/libraries/botbuilder/src/botFrameworkAdapter.ts +++ b/libraries/botbuilder/src/botFrameworkAdapter.ts @@ -235,7 +235,7 @@ export class BotFrameworkAdapter extends BotAdapter { parameters.channelData = { tenant: { id: reference.conversation.tenantId } }; // Permanent solution is to put tenantId in conversation.tenantId - parameters.conversation = { tenantId: reference.conversation.tenantId }; + parameters.tenantId = reference.conversation.tenantId; } diff --git a/libraries/botframework-schema/src/index.ts b/libraries/botframework-schema/src/index.ts index 8fafe66f4c..b734625d92 100644 --- a/libraries/botframework-schema/src/index.ts +++ b/libraries/botframework-schema/src/index.ts @@ -117,6 +117,10 @@ export interface ConversationAccount { * Indicates the type of the conversation in channels that distinguish between conversation types */ conversationType: string; + /** + * This conversation's tenant ID + */ + tenantId: string; /** * Channel id for the user or bot on this channel (Example: joe@smith.com, or @joesmith or * 123456) @@ -501,6 +505,10 @@ export interface ConversationParameters { * (Optional) Topic of the conversation (if supported by the channel) */ topicName?: string; + /** + * (Optional) The tenant ID in which the conversation should be created + */ + tenantId?: string; /** * (Optional) When creating a new conversation, use this activity as the initial message to the * conversation From b40edff3e5be2d287351aca925de2fa3354cbdf0 Mon Sep 17 00:00:00 2001 From: Ben Brown Date: Fri, 8 Feb 2019 15:27:33 -0600 Subject: [PATCH 7/7] update comment --- libraries/botbuilder/src/botFrameworkAdapter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/botbuilder/src/botFrameworkAdapter.ts b/libraries/botbuilder/src/botFrameworkAdapter.ts index 6468d90339..cb6a20bf00 100644 --- a/libraries/botbuilder/src/botFrameworkAdapter.ts +++ b/libraries/botbuilder/src/botFrameworkAdapter.ts @@ -233,7 +233,7 @@ export class BotFrameworkAdapter extends BotAdapter implements IUserTokenProvide // Putting tenantId in channelData is a temporary solution while we wait for the Teams API to be updated parameters.channelData = { tenant: { id: reference.conversation.tenantId } }; - // Permanent solution is to put tenantId in conversation.tenantId + // Permanent solution is to put tenantId in parameters.tenantId parameters.tenantId = reference.conversation.tenantId; }