Skip to content

Conversation

@heyitsaamir
Copy link
Collaborator

NOTE: This is reopening #427 because it needed some design work.

Add support for Targeted Messages
This PR introduces support for sending targeted messages - messages delivered privately to a specific recipient within a conversation.

Key Updates:

Added an isTargeted boolean parameter to the send, update, reply and delete APIs. When enabled, the message is sent privately to the Recipient.Id specified in the activity payload.

We append isTargetedActivity=true as a query parameter in API URLs when isTargeted is set, allowing backend services to correctly process these requests.

Comment on lines +36 to +41
let url = `${this.serviceUrl}/v3/conversations/${conversationId}/activities`;
if (isTargeted) {
url += '?isTargetedActivity=true';
}

const res = await this.http.post<Resource>(url, params);
Copy link
Collaborator Author

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.post should have support for that

Copy link
Collaborator Author

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.

Comment on lines +36 to +41
let url = `${this.serviceUrl}/v3/conversations/${conversationId}/activities`;
if (isTargeted) {
url += '?isTargetedActivity=true';
}

const res = await this.http.post<Resource>(url, params);
Copy link
Collaborator Author

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.

from: this.ref.bot,
conversation: this.ref.conversation,
// Set recipient from ref.user if provided (for targeted messages)
...(this.ref.user && { recipient: this.ref.user }),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ShanmathiMayuramKrithivasan does this work with streaming? have you tested that?

* @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) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do targetedRecipientUserId here?
So users can do app.send(conversationId, "string message", targetedRecipientUserId); Right now it's not clear that isTargeted will lead to the method throwing under some circumstances.

With targetedRecipientUserId, toActivityParams does the work of setting the recipient id in the activity.

from: ref.bot,
conversation: ref.conversation,
// Set recipient from ref.user if provided (for targeted messages)
...(ref.user && { recipient: ref.user }),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Putting this logic in toActivityParams might be better/cleaner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants