How to capture user_country/city in botframework web channel? - botframework

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!

Related

MS Teams Incoming Webhook issue

I've created an incoming Teams Webhook connector within a Teams group (using the method below).
I can successfully curl to the webhook internally and get the message to display ok.
MS have checked my tenant and access is as expected.
When I apply my URL for the webhook to any external service they eventually come back stating there was a problem detected with the webhook (Please make sure that your webhook endpoint of xxx is responding with a 2xx response code within 30 seconds of initial connection.)
Can anyone advise what else may need to be done?
Thanks
In Microsoft Teams, choose More options (⋯) next to the channel name and then choose Connectors.
Scroll through the list of Connectors to Incoming Webhook, and choose Add.
Enter a name for the webhook, upload an image to associate with data from the webhook, and choose Create.
Copy the webhook to the clipboard and save it. You'll need the webhook URL for sending information to Microsoft Teams.
Choose Done.
Incoming webhooks are special type of Connector in Teams that provide a simple way for an external app to share content in team channels and are often used as tracking and notification tools. Teams provides a unique URL to which you send a JSON payload with the message that you want to POST, typically in a card format. Cards are user-interface (UI) containers that contain content and actions related to a single topic and are a way to present message data in a consistent way. Please test the incoming webhook url using postman and let us know the payload result or status code. Would be help full for us to understand more.

Google Meet integration api (like Hangouts app for Slack)

I want to utilise Google Meet api, which is used in Hangouts integration for Slack, description follows
TL;DR:
Links such as https://meet.google.com/new?gid=123&gd=qwe987 can be generated, so a modal is shown which can ask user's confirmation and then some request is sent from user's browser (where the Google Meet page is opened) to some endpoint (probably it is determined from gid which seems to be google application id). Is there a way to configure my application to have a webhook, so I can generate these custom links?
There's Google+ Hangouts app for Slack. Here's how it works (after you add the app in your workspace):
you send /hangout command in any Slack channel
slackbot sends an "Only visible to you" message in this channel with a link to start a new hangout. it looks smth like this (I changed data in the link): https://meet.google.com/new?gid=691521906844&gd=THTJ30X6W%7CU01113BD13M%7CD01113BDB5Z%7Csuren%7C%7C1846381238693%7C1%7CB01QFGG5GJF%7CE1MDm4DWcuVa0RbN5ZT9o5KF
when you visit the link, a new meeting is started instantly, and the page shows modal with text "To bring others into this video call, post a link it to your Slack channel" with buttons 'Cancel' and 'Post'.
when you click 'Post', a new message is sent to the Slack channel, where the command was sent. Text is "#Suren Khorenyan has started a Google+ Hangout and would like you to join. Join Hangout." and contains a link to the meet, which was created previously
How can I utilise this integration for another app, like Mattermost (or anything else like Telegram chats via bots)?
As I see, data in the url slightly changes. Probably it's payload for Google Meet to trigger Slack to send a message with link to the channel.
gid seems to be something like google app id
gd seems to be something like google data. If I url-decode it, it becomes THTJ30X6W|U01113BD13M|D01113BDB5Z|suren||1846381238693|1|B01QFGG5GJF|E1MDm4DWcuVa0RbN5ZT9o5KF. This is some kind of payload, separated by pipes (obviously), but I don't know what any part of this means (suren is my username in the Slack workspace, probably this is used for creating an invitation message).
When I click Post, this happens:
a new POST request to https://hooks.slack.com/services/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 is sent with form-data
hangout_id: 1812381238693
hangout_url: https://meet.google.com//abc-iuqx-def
a new message is posted to the Slack channel
Google meet somehow knows where to post back! Is this configured at the Google application (application id is provided via gid)? How can I configure my application for such behaviour? Where can I setup webhook url?
If we breakdown the request, we can see that url contains some parts of the gd payload:
THTJ27X6W - this is the first part of the gd payload
B01ABCD5GJF - last but one
E1MDm4DWcuVa0RbK5ZT9o5KD - the last part of the gd payload
and form-data contains:
hangout_id - this is in the gd payload after my name
hangout_url - obviously, this is the url for the new created meeting
How can I change it for my needs?
I created a new application at Google APIs dashboard (here console.developers.google.com/apis), but can't find any docs for this integration. There's Google+ Hangouts API in API Library, but it says Apps will continue to function until April 25, 2017..
I tried to approach it from another side:
In the API Library there's Google Calendar. I found mattermost-hangout app on GitHub (had to update it a bit, so it works with updated api). Here's how it works:
oauth2 for authorising at google (single account)
it handles POST request, which is meant to be received from Mattermost (triggered by a slash command),
creates a new calendar event using Google Calendar API (with conference),
takes hangouts url from the response and sends a new message in the Mattermost channel with invitation to join the meeting.
But it has some downsides:
you have to use one account to authorise all event creation events (yeah, it can be upgraded to authorise any number of users, but it'll be inconvenient. why to force anyone to provide access to their Google Account, when Google Meet authorisation just happens in browser, we don't need to create events)
account, used for auth, now has events in his calendar. of course, events can be deleted, but it's not the way.
Is there any documentation on utilising gid and gd params?
Generally, I want to find a way to configure a webhook in my app, so when Google Meet finds my application's ID in the gid query param, it looks at the app's config and sends a request to my app (previously configured endpoint (I assume it works this way)).
Of course there's a chance that it's some kind of internal API and it cannot be used by everyone, but I could not find any information on this.

Microsoft Healthbot API Get scenario stack information

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!

Can I call a Microsoft BotBuilder like calling a function?

I am trying to build a bot and use it within a chat app. I think Microsoft Bot Builder is the one for me.
I looked into its documentations and tried them in the emulator.
I noticed that in these examples, you send texts to the bot either using
"consoleconnector" or "chatconnector", as the example shows.
server.post('/api/messages', connector.listen());
// Receive messages from the user and respond by echoing each message
back (prefixed with 'You said:')
var bot = new builder.UniversalBot(connector, function (session) {
session.send("You said: %s", session.message.text);
});
I don't want a new endpoint. I want to call the bot like calling a function: give the incoming message from a user and the function returns bot's response.
Is it possible? If yes, please tell me how to do it.
If it is not possible, then only way is to call it as a rest API as shown above.
In this case, do i still need "MICROSOFT_APP_ID" and "MICROSOFT_APP_PASSWORD"?
Note that, I don't want to deploy the bot to azure or aws now. I want to use it local.
Could anyone help me explain these? Thanks in advance!
The Bot Framework is built to function as an API - it takes a request and sends a response. The framework doesn't provide a callback or promise to capture the response so this approach simply wouldn't work. Take a look at the DirectLine API if you want to embed the framework within another application.
You need to use the MS App id and password for all channels apart from the Emulator. If you use DirectLine API, you will also have to pass a secret token.

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