Microsoft Healthbot API Get scenario stack information - botframework

H, I'm working on a healthcare project which is using Microsoft Healthcare Bot as a tool. I followed the GitHub: https://github.com/Microsoft/HealthBotContainerSample/, and set it up successfully. right now what I can subscribe from the bot is activity property, using the below sample code:
botConnection.postActivity({type: "activity", value: jsonWebToken, from: user, name: "InitAuthenticatedConversation"}).subscribe(function (id) {
});
botConnection.activity$.filter(function(activity)
{
return activity.type === "activity"
})
.subscribe(function (activity)
{
console.log(activity);
});
and the first screenshot is what i get:
However, there is one thing I can't find any corresponding API, if I interact with bot on Azure, there is an Object with contains scenario stack, intent, score and so on (see the screenshot). But I can't find which API can help me retrieve this object,So, how to retrieve the object showing in the watch window?

Unfortunately, it does not look like there is a way in which a trace can be logged outside of the Scenario Designer for the HealthBot. I tested this and it looks like the trace is not emitted by the bot as any sort of event or message activity and only outputs from the bot, itself.
There are a couple avenues you can take, however.
One, if you sign up for Application Insights in Azure and include the Instrumentation Key, then you can log how the application (i.e. bot) is performing. This will capture any trace events emitted by the bot, however, the telemetry is not the same. It will allow you to see when they are occurring. The below screenshot from Azure shows an example.
To add in Application Insights, in your HealthBot in Azure, navigate to Integration => Secrets. You can then add the Instrumentation Key and save. It generally takes a few moments for activity to populate when viewing Application Insights, so be patient.
The second thing you can do is submit a Feature Request on their GitHub repo here requesting trace events be made available externally for logging and inspection.
Additionally, there is a Microsoft TechCommunity that you can participate in. I don't know if it is monitored for issues/requests, but it is worth trying.
Hope of help!

Related

Can I create a configuration page for a Teams bot app?

I'm building my first Teams app which will have two primary functions:
Proactively send a message to the channel (the bot is installed into) when a specific event occurs on my backend.
Members of the channel reacts to the message via actions.
I finally have a pretty good idea of how to set this up (I think) - but one part I'm missing is that in order to identify the specific app installation as belonging to one of my customers, I need to be able to allow the installing user to supply extra information like e.g. an API-key so that I can associate the specific channel with my specific customer.
Is there any way of doing this with a bot app? I've found examples for creating a configuration page, but they all seem to be associated with tab apps?
I could of cource have the bot ask the user for the information - but maybe there's a "cleaner" way?
Any examples or tutorials would be greatly appreciated as I find it rather hard to get stuff working using Microsoft's own examples etc. :)
Thanks a lot!
When you receive any message from the user, either by typing to your bot, or even installing it into a channel, group chat, or personal context (where you get the conversationUpdate event), you are able to get specific details off of the activity object. If the user sends a message, for instance, then the text property on the activity object will have a value. Incidentally, this is the same activity you will use to get the conversation details you need for the Proactive message.
With regards your question, the activity class also includes a tenantId property, hanging off the conversation property. This is the unique Microsoft 365 Id for the tenant, which would be what I'd suggest to uniquely identify them for your API, or licensing, or similar.

How to capture user_country/city in botframework web channel?

I would like to capture end-user location (country/city) in Application insights form azure botframework chatbot running on web chat channel. App insights instrumentation is already in place page view and custom events being collected, but it seems that the client_City and client_CountryOrRegion are not populated correctly. Is there a specific channel or webservice configuration?
Geolocation data can be accessed using the below method. This will provide you with the longitude and latitude providing the user grants access to this data.
You will then need another process or library to convert the location data to a physical location in the real world.
navigator.geolocation.getCurrentPosition( async (position) => {
const { latitude, longitude } = position.coords;
console.log(latitude, longitude)
})
There are some NPM packages that can do some of this for you, as well.
If you look at my posted answer here, you can see an example I provided on how to get location data for use in generating and displaying a map as a feature of the bot.
Please note that, in the above answer, the bot is responding to a request to display a map, is sending the activity which is then picked up by Web Chat. Web Chat, upon receiving the request, is then getting the location data and displaying the map.
In your case, you will want to send the data back to the bot for the bot to then do something with. You can refer to Web Chat's b.piggyback-on-outgoing-activities sample on how to do this.
Hope of help!

Change the CSS of Chatbot embedded as IFRAME

ISSUE:
Today my chat bot stopped working and started giving the following error. No changes were made on my end when this started happening.
I could not find any error in console log. Then I tested the bot with Emulator and in Azure Portal's Test in Webchat feature and the bot worked fine. This bot is using webchat (iframe embed) as well as DirectLine channel. The DirectLine channel works fine it is only the webchat that is not working.
So to test my theory that I am getting the error because of webchat getting updated by Microsoft. I used the embed code in Azure Portal to use the latest webchat and the webchat channel started working.
BRIEF HISTORY:
To modify the UI of the webchat I used this method to modify the UI of the IFrame of my bot. This method requires to download the source of IFrame, create an HTML page and use that page as a source of your IFRAME in your website (you can see the customization in the image).
Now that I started getting the issue I mentioned above, I tried to do the same thing with the latest version of webchat but it is not working. The webchat is not sending messages and I cannot find what CSS file this new version of webchat is using.
WHAT I NEED GUIDANCE ON:
Either a way to continue using the old webchat with the proper UI
OR
How to update the UI of this new webchat version?
I can't advise on fixing the iframe version, but this already wasn't officially supported, and with the latest webchat update Microsoft is moving more to recommending botframework-webchat (directline) to format the UI. A good place to start is the branding sample.
That sample doesn't spell out the options in the code, but if you take a look at the default options file, that should give you everything you need to customize the chat the way you want.
What this does not do is set up the header that used to be present in ootb webchat (and which I see you customized in your example). Now the best way is to do this in html/css, and you probably can just reuse what you did for your custom option. I just created an additional DIV, set it to height: 40px;, then set the webchat DIV to height: calc(100% - 40px);. Anyone who's good with HTML can probably come up with better than this, essentially you just build your page however you want at that point and the webchat implementation just controls the chat area itself (essentially send box and response/bubble area). I also added a custom button to my header.
<div id="chatbotTitle"><h3 style="padding-left:10px;">OEM CSC Support Bot</h3><button class="btn" id="transcriptButton">Email Transcript</button></div>
<div id="webchat" role="main"></div>
The error you are receiving is not a web chat issue. It is an issue in your bot that is being reported via web chat because that is the client being used.
Usually, this error is referring to an incoming activity that your bot doesn't know how to handle (i.e. your bot logic). For example, you have a waterfall step in your main dialog that, depending on the user's response, opens a component dialog. That dialog gets user information (name, age, etc.) that, when complete, returns to the main dialog. However, the next step isn't prepared as perhaps the user exited that dialog prematurely or didn't answer all the questions as expected.
Whatever the case may be, because it isn't setup to handle the incoming activity, it isn't returning the dialog's turn status. You will need to debug your code, stepping thru it, to see which "step" is the root cause.
For me, I have experienced this when I set up Web Chat to send an event back to my bot. My bot didn't know what to do with the incoming event-type activity and would produce that error.
Hope of help!

How to update an existing activity in WebChat

My scenario is: I send card attachments each with an AcceptButton to users. When 1 user clicks on that button, ideally I want to disable all similar buttons (of the same offer) for all users. I am storing conversation details of each user, and I know the ActivityId of each message-with-said-button (it follows a certain string format).
My issue is similar to this and this but for WebChat not Teams.
I did try those solutions but I got the error "Method not allowed" for both UpdateActivityAsync() and DeleteActivityAsync(). Then I read here that UpdateActivity is not supported in WebChat. (But might be available in the future?)
I would like any visual indication that the offer is no longer available. (Right now, they receive an "Offer was already accepted by {UserX}" which would still be in place on top of changing the card/message.)
Is there a way to do this via backChannel? I can trigger an event and pass the ActivityId (tested by showing a simple alert()) but how do I apply changes to that specific activity?
Per this comment in Web Chat's source code and this open issue in the Web Chat repository for adding support for deleteActivity and updateActivity, Update Activity events are not currently supported in Web Chat. Unfortunately, there is currently no way to really update an activity in Web Chat.
Hope this helps!

Need suggestions in getting the conversation details

I am creating a bot using MS Bot framework - NodeJs. The below information needs to be captured for logging (Using the bot.use method i.e. IMiddleware).
Receive:
a. UserId
b. UserInput (text)
c. ConversationId
Send:
1. Name of Intent or dialog name that handled this (that handled the user input text)
2. Bot output text
3. ConversationId
4. UserId
I am unable to get the required detail for the 'send'. Can anyone provide me some suggestions on this.
Thanks.
I believe your main struggle is to log the name of intent or dialog. You won't know it in your send middleware if you haven't captured it during the routing phase. Once the Bot Framework figured out where to send the incoming message, it just invokes that function.
These two articles may help you get what you want. Just recently I played with capturing the conversation's breadcrumbs and also logging a full transcript:
http://www.pveller.com/smarter-conversations-part-3-breadcrumbs/
http://www.pveller.com/smarter-conversations-part-4-transcript/
If you need to build a reliable capture engine, I would suggest that you didn't use the session.privateConversationData like I did and instead built your own storage/log infrastructure to push the events to. Just stream them out with a timestamp and conversationId and reconcile on the other end later. The asynchronous nature of everything the bot framework does internally will be haunting you along the way so that's why. Plus, once you scale out beyond testing on a few users and your bot spans multiple processes, you will be out of the single-threaded event loop.

Resources