Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
Fixex #1937 - change method for locating adapter inside bot
Browse files Browse the repository at this point in the history
  • Loading branch information
benbrown committed Mar 18, 2020
1 parent 62ab6d4 commit ec98586
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
6 changes: 3 additions & 3 deletions packages/botbuilder-adapter-slack/src/botworker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ export class SlackBotWorker extends BotWorker {
msg.conversation.thread_ts = src.incoming_message.channelData.thread_ts;
}

msg = this.getConfig('context').adapter.activityToSlack(msg);
msg = this.getConfig('adapter').activityToSlack(msg);

const requestOptions = {
uri: src.incoming_message.channelData.response_url,
Expand Down Expand Up @@ -336,7 +336,7 @@ export class SlackBotWorker extends BotWorker {
* @param update An object in the form `{id: <id of message to update>, conversation: { id: <channel> }, text: <new text>, card: <array of card objects>}`
*/
public async updateMessage(update: Partial<BotkitMessage>): Promise<any> {
return this.getConfig('context').adapter.updateActivity(
return this.getConfig('adapter').updateActivity(
this.getConfig('context'),
update
);
Expand All @@ -356,7 +356,7 @@ export class SlackBotWorker extends BotWorker {
* @param update An object in the form of `{id: <id of message to delete>, conversation: { id: <channel of message> }}`
*/
public async deleteMessage(update: Partial<BotkitMessage>): Promise<any> {
return this.getConfig('context').adapter.deleteActivity(
return this.getConfig('adapter').deleteActivity(
this.getConfig('context'),
{
activityId: update.id,
Expand Down
6 changes: 3 additions & 3 deletions packages/botkit/src/botworker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ export class BotWorker {
);

// create a turn context
const turnContext = new TurnContext(this.getConfig('context').adapter, activity as Activity);
const turnContext = new TurnContext(this.getConfig('adapter'), activity as Activity);

// create a new dialogContext so beginDialog works.
const dialogContext = await this._controller.dialogSet.createContext(turnContext);
Expand All @@ -278,7 +278,7 @@ export class BotWorker {

// Create conversation
const parameters: ConversationParameters = { bot: reference.bot, members: [reference.user], isGroup: false, activity: null, channelData: null };
const client = this.getConfig('context').adapter.createConnectorClient(reference.serviceUrl);
const client = this.getConfig('adapter').createConnectorClient(reference.serviceUrl);

// Mix in the tenant ID if specified. This is required for MS Teams.
if (reference.conversation && reference.conversation.tenantId) {
Expand Down Expand Up @@ -312,7 +312,7 @@ export class BotWorker {
if (response.serviceUrl) { request.serviceUrl = response.serviceUrl; }

// Create context and run middleware
const turnContext: TurnContext = this.getConfig('context').adapter.createContext(request);
const turnContext: TurnContext = this.getConfig('adapter').createContext(request);

// create a new dialogContext so beginDialog works.
const dialogContext = await this._controller.dialogSet.createContext(turnContext);
Expand Down
6 changes: 5 additions & 1 deletion packages/botkit/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1077,14 +1077,18 @@ export class Botkit {
}

let worker: BotWorker = null;
const adapter = custom_adapter || config.context.adapter || this.adapter;
const adapter = custom_adapter || (config.context && config.context.adapter) ? config.context.adapter : this.adapter;

if (adapter.botkit_worker) {
const CustomBotWorker = adapter.botkit_worker;
worker = new CustomBotWorker(this, config);
} else {
worker = new BotWorker(this, config);
}

// make sure the adapter is available in a standard location.
worker.getConfig().adapter = adapter;

return new Promise((resolve, reject) => {
this.middleware.spawn.run(worker, (err, worker) => {
if (err) {
Expand Down

0 comments on commit ec98586

Please sign in to comment.