Skip to main content

Notifications

Copilot Studio - Topic Creation & Management
Unanswered

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

(0) ShareShare
ReportReport
Posted on 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
    HenryJammes on at
    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
    anshul001 4 on at
    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.

  • 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
    HenryJammes on at
    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
    anshul001 4 on at
    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
    HenryJammes on at
    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

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

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

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,666

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,996

Leaderboard

Featured topics