web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Copilot Studio / How to get Virtual Age...
Copilot Studio
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!

I have the same question (0)
  • HenryJammes Profile Picture
    on at

    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

  • anshul001 Profile Picture
    4 on at

    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 at

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

  • Jameslew_MSFT Profile Picture
    on at

    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.

  • anshul001 Profile Picture
    4 on at

    @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.

  • HenryJammes Profile Picture
    on at

    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

     

     

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Copilot Studio

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 255 Super User 2025 Season 2

#2
Romain The Low-Code Bearded Bear Profile Picture

Romain The Low-Code... 205 Super User 2025 Season 2

#3
S-Venkadesh Profile Picture

S-Venkadesh 101 Moderator

Last 30 days Overall leaderboard