-
Notifications
You must be signed in to change notification settings - Fork 25
Add support for Targeted Messages" #430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -399,12 +399,20 @@ export class App<TPlugin extends IPlugin = IPlugin> { | |
| * send an activity proactively | ||
| * @param conversationId the conversation to send to | ||
| * @param activity the activity to send | ||
| * @param isTargeted when true, sends the message privately to the recipient specified in activity.recipient | ||
| */ | ||
| async send(conversationId: string, activity: ActivityLike) { | ||
| async send(conversationId: string, activity: ActivityLike, isTargeted: boolean = false) { | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we do targetedRecipientUserId here? With |
||
| if (!this.id) { | ||
| throw new Error('app not started'); | ||
| } | ||
|
|
||
| const activityParams = toActivityParams(activity); | ||
|
|
||
| // Validate that recipient is provided for targeted messages | ||
| if (isTargeted && !activityParams.recipient) { | ||
| throw new Error('activity.recipient is required for targeted messages'); | ||
| } | ||
|
|
||
| const ref: ConversationReference = { | ||
| channelId: 'msteams', | ||
| serviceUrl: this.api.serviceUrl, | ||
|
|
@@ -417,9 +425,10 @@ export class App<TPlugin extends IPlugin = IPlugin> { | |
| id: conversationId, | ||
| conversationType: 'personal', | ||
| }, | ||
| user: isTargeted ? activityParams.recipient : undefined, | ||
| }; | ||
|
|
||
| const res = await this.http.send(toActivityParams(activity), ref); | ||
| const res = await this.http.send(activityParams, ref, isTargeted); | ||
| return res; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -148,7 +148,7 @@ export class HttpPlugin implements ISender { | |
| this._server.close(); | ||
| } | ||
|
|
||
| async send(activity: ActivityParams, ref: ConversationReference) { | ||
| async send(activity: ActivityParams, ref: ConversationReference, isTargeted: boolean = false) { | ||
| const api = new Client( | ||
| ref.serviceUrl, | ||
| this.client.clone({ | ||
|
|
@@ -160,16 +160,18 @@ export class HttpPlugin implements ISender { | |
| ...activity, | ||
| from: ref.bot, | ||
| conversation: ref.conversation, | ||
| // Set recipient from ref.user if provided (for targeted messages) | ||
| ...(ref.user && { recipient: ref.user }), | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Putting this logic in toActivityParams might be better/cleaner |
||
| }; | ||
|
|
||
| if (activity.id) { | ||
| const res = await api.conversations | ||
| .activities(ref.conversation.id) | ||
| .update(activity.id, activity); | ||
| .update(activity.id, activity, isTargeted); | ||
| return { ...activity, ...res }; | ||
| } | ||
|
|
||
| const res = await api.conversations.activities(ref.conversation.id).create(activity); | ||
| const res = await api.conversations.activities(ref.conversation.id).create(activity, isTargeted); | ||
| return { ...activity, ...res }; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isTargetedActivity should be a URL param.
http.postshould have support for thatThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do the same for all the methods below as well.