Skip to content

Commit 5675853

Browse files
authored
Add optional conversation ref parameter to send and fix tenant app graph token during app.process (#291)
1. Just tested out `send` for the group oauth scenario, and we need to plumb conversation ref through to `send` for this to work. 2. Also tested out the app-graph scenario, and it was defaulting to using `this._tokens.graph?.toString()` which wasn't working in calling graph successfully. Tested both scenarios now, and both are working correctly now.
1 parent ada7676 commit 5675853

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

packages/apps/src/app.process.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,11 @@ export async function $process<TPlugin extends IPlugin>(
124124
}
125125

126126
const send = context.send.bind(context);
127-
context.send = async (activity: ActivityLike) => {
128-
const res = await send(activity);
127+
context.send = async (activity: ActivityLike, conversationRef?: ConversationReference) => {
128+
const res = await send(activity, conversationRef);
129129

130130
this.onActivitySent(sender, {
131-
...ref,
131+
...(conversationRef ?? ref),
132132
sender,
133133
activity: res,
134134
});

packages/apps/src/app.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -535,17 +535,19 @@ export class App<TPlugin extends IPlugin = IPlugin> {
535535
return res.token;
536536
}
537537

538-
protected async getOrRefreshTenantToken(tenantId?: string) {
538+
protected async getOrRefreshTenantToken(tenantId: string) {
539539
let appToken =
540-
this.tenantTokens.get(tenantId || 'common') || this._tokens.graph?.toString();
541-
if (this.credentials && !appToken) {
540+
this.tenantTokens.get(tenantId);
541+
if (this.credentials && !this.tenantTokens.get(tenantId)) {
542542
const { access_token } = await this.api.bots.token.getGraph({
543543
...this.credentials,
544544
tenantId: tenantId,
545545
});
546546

547+
this.log.debug(`refreshing tenant token for ${tenantId}`);
548+
547549
appToken = access_token;
548-
this.tenantTokens.set(tenantId || 'common', access_token);
550+
this.tenantTokens.set(tenantId, access_token);
549551
}
550552

551553
return appToken;

packages/apps/src/contexts/activity.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,9 @@ export interface IActivityContext<T extends Activity = Activity>
126126
/**
127127
* send an activity to the conversation
128128
* @param activity activity to send
129+
* @param conversationRef optional conversation reference to send the activity to. By default, it will use the activity's conversation reference.
129130
*/
130-
send: (activity: ActivityLike) => Promise<SentActivity>;
131+
send: (activity: ActivityLike, conversationRef?: ConversationReference) => Promise<SentActivity>;
131132

132133
/**
133134
* reply to the inbound activity
@@ -199,8 +200,8 @@ export class ActivityContext<T extends Activity = Activity>
199200
}
200201
}
201202

202-
async send(activity: ActivityLike) {
203-
return await this._plugin.send(toActivityParams(activity), this.ref);
203+
async send(activity: ActivityLike, conversationRef?: ConversationReference) {
204+
return await this._plugin.send(toActivityParams(activity), conversationRef ?? this.ref);
204205
}
205206

206207
async reply(activity: ActivityLike) {
@@ -286,7 +287,7 @@ export class ActivityContext<T extends Activity = Activity>
286287
],
287288
}),
288289
],
289-
}
290+
}, convo
290291
);
291292
}
292293

0 commit comments

Comments
 (0)