Skip to main content

Notifications

Community site session details

Community site session details

Session Id : 3MU7Fpod1WczQKUhm9DI5X
Copilot Studio - Topic Creation & Management
Unanswered

How to get Virtual Agent Topic from a message ID using Direct Line API

Like (0) ShareShare
ReportReport
Posted on 20 Mar 2023 06:44:36 by 4

I am trying to intercept the request and response that are sent to a virtual agent bot using DirectLine (Bot Framework). I have subscribed to the directline's activity using:

`directLine.activity$.subscribe(message => console.log(message));`

From this I get the message object which I can manipulate before displaying it in the client. What I want is to find the topic (i.e. the virtual agent topic) that the bot has selected (using the trigger phrase) for the conversation. Based on the topic I want to do different things, how can I get it ?

Here is an example of the message I get:

{
type: 'message',
id: 'IvkoXGKm9ZKIHdjv6foMM6-in|0000001',
timestamp: '2023-03-20T05:26:13.7251392Z',
channelId: 'directline',
from: { id: '5903103d-ad35-496c-acb4-9f797198ab51', name: 'John' },
conversation: { id: 'IvkoXGKm9ZKIHdjv6foMM6-in' },
textFormat: 'markdown',
membersAdded: [],
membersRemoved: [],
reactionsAdded: [],
reactionsRemoved: [],
text: 'Can you tell me your name ?',
speak: '<speak version="1.0" xml:lang="en-US" xmlns:mstts="http://www.w3.org/2001/mstts" xmlns="http://www.w3.org/2001/10/synthesis">Can you tell me your name ?</speak>',
attachments: [],
entities: [],
replyToId: 'IvkoXGKm9ZKIHdjv6foMM6-in|0000000',
listenFor: [],
textHighlights: []
}


I expect that there should be a way to get the topic from the message. Any help would be appreciated. Thanks!

  • HenryJammes Profile Picture
    on 22 Mar 2023 at 13:26:23
    Re: How to get Virtual Agent Topic from a message ID using Direct Line API

    I too don't seem to receive the custom event as an activity from the Direct Line API in my tests.

     

    I created a dialog emitting a custom event that contains the dialog schema name as a value:

     

    HenryJammes_0-1679491426687.png

     

    I then call that dialog from my topic:

     

    HenryJammes_1-1679491488543.png

     

    But the Direct Line only seems to retrieve activity of type 'message', and not my custom event:

     

    HenryJammes_2-1679491572280.png

     

     

  • anshul001 Profile Picture
    4 on 22 Mar 2023 at 05:25:35
    Re: How to get Virtual Agent Topic from a message ID using Direct Line API

    @Jameslew_MSFT  Yes I am emitting a Custom Event from composer (using emit a custom event) and redirecting to that dialogue(topic) from virtual agent. I am using Direct Line channel to subscribe to the activities of the virtual agent bot.

  • Jameslew_MSFT Profile Picture
    on 21 Mar 2023 at 23:50:48
    Re: How to get Virtual Agent Topic from a message ID using Direct Line API

    I have not tried this specifically; what sort of event are you emitting?  Specifically type "Custom Event?  I'd need to verify we support that one being emitted from PVA.  There's also an Activity of type Event that I know we use for calling skills.  LMK what you're using and I can check.

  • HenryJammes Profile Picture
    on 21 Mar 2023 at 14:28:19
    Re: How to get Virtual Agent Topic from a message ID using Direct Line API

    I'm not sure as I haven't tested this before.
    @Jameslew_MSFT, do you think that approach would work?

  • anshul001 Profile Picture
    4 on 21 Mar 2023 at 13:31:54
    Re: How to get Virtual Agent Topic from a message ID using Direct Line API

    Hi @HenryJammes 

     

    I emitted an event by extending virtual agent using bot framework composer , and emitted an custom event by creating a dialog in composer. In virtual agent I redirected to that topic (i.e. dialog). But I am not getting that event in "directLine.activity$.subscribe".

     

    (I confirmed that the event is being emitted by using a trigger based on that)

  • HenryJammes Profile Picture
    on 20 Mar 2023 at 11:42:17
    Re: How to get Virtual Agent Topic from a message ID using Direct Line API

    Hi @anshul001,

     

    I don't think that's possible. Direct Line has only what it needs to send/receive messages to the user. The internals of the bots operation, such as triggered topic, scores, etc., aren't relevant on the client side (and could be exposing data that the developer doesn't want to share).

     

    I haven't explored it, but have you looked at emitting custom events, (that I'm assuming could be transparent to your end users) so that the client knows in what context/topic a message is sent? Events and triggers for adaptive dialogs - Bot Service | Microsoft Learn

     

    Henry

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Thomas Rice – Community Spotlight

We are honored to recognize Thomas Rice as our March 2025 Community…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,508 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,369 Most Valuable Professional

Leaderboard

Featured topics

Loading started