How to read the data passed from webchat payload to the bot in bot framework composer in dirext line api? - bot-framework-composer

I am trying to read a param passed from webchat by using directline api to read those values for steering the conversation in bot.
But I am getting 'A scope of req was not found' when accessing req.qury.passedValue.

Related

Microsoft Bot Framework (SDK4 Nodejs) : How to make the bot perform some action like customer authentication using api?

I want the Microsoft Bot Framework Chat Bot to verify my customer using freshservice api.
I have already asked the user for their username and password (corresponding to the : company-domain.freshservice.com) and stored the customers details using state accessor (As shown in the docs provided for SDK4 of Microsoft Bot Framework). Now after obtaining the details, I want the bot to send a http request to freshservice api and authenticate the customer. And display the result of the authentication of the bot to the Chat window (Currently the Bot Framework Emulator). Please help as I am not able to figure out a way to do it.
The Freshservice API is built around CURL, so it's a little difficult to see how to use it in Node. I've taken the first example and converted it for you:
From:
curl -u user#yourcompany.com:test -H "Content-Type: application/json" -X GET https://domain.freshservice.com/helpdesk/tickets.json
To:
// Convert to base64
const loginInfo = Buffer.from(`${ username }:${ password }`).toString('base64');
const response = await axios.get(`https://<yourDomain>.freshservice.com/helpdesk/tickets.json`, {
headers: {
'Content-Type': 'application/json',
Authorization: `Basic ${ loginInfo }`
}
});
await context.sendActivity(JSON.stringify(response.data, null, 2));
This will result in the full JSON response:
How you choose to display that will be up to you.
Notes:
You'll need to install axios (or some other service that can make GET requests) npm i axios
Freshservice supports OAuth, which is also supported in BotFramework
I HIGHLY recommend going this route because it will mean you don't have to figure out storing and encrypting user login information. It's significantly more secure and less of a headache for you. Basically, instead of storing user/pass, it will present the user with a login prompt. When logged it, it returns a token that you'll store and use that to make requests. Now, if an attacker wanted to steal usernames and passwords, their only route to do so is the Freshservice API. If you're storing user/pass yourself, they can also try to attack your bot client, bot conversation history, and your bot storage.
To get started, read Add authentication to your bot and use the Bot Authentication Sample as a guide.

Fetching user profile in Bot with MS Teams channel using node sdk v4

I am working with Microsoft Bot Framework SDK v3, as well as v4, for node.js. I have one v3 bot & one v4 bot, both with MS teams channel, but I'm not able to get users' profile details in bot code for v4 bot. (exactly looking for userprincipalname )
In v3 I'm using TeamsChatConnector which has fetchMembers() which fetches users details, but things have changed in v4. It is also known as 'Fetching the team roster'.
Here is the documentation
In the v4 bot, there is BotFrameworkAdapter which is not specific to MS teams or any other channel. If I inspect activity object, I can see from the 'from' property, it only has user's name:'lastName,First name' AND
AAD object id, but not userprincipalname which is usually an email address.
How can I get access to users email address or userprincipalname in v4 BOT code if users is using MS teams channel?
connector.fetchMembers(
(<builder.IChatConnectorAddress>session.message.address).serviceUrl,
conversationId,
(err, result) => {
if (err) {
session.endDialog('There is some error');
}
else {
session.endDialog('%s', JSON.stringify(result));
}
}
);
Leaving this here if somebody is as lost as me. You can make a request to the REST API, getting that information. Here you can see the endpoint
And here you can see how to set up the headers: Link
Combining both, making a GET will return context of the users in a team chat or 1:1 chat.

Push notifications using Firebase Cloud Function iOS

Trying to send remote push notifications through firebase cloud functions. Resources I've been following achieves this through sendToDevice method, which takes a String as an argument. A resource from GitHub says its a "device notification token" that is retrieved when user agrees to receive notifications in app. Firebase says its a "registration token that comes from the client FCM SDKs". What should be the input here, and how to I retrieve it?
// Send notification to device via firebase cloud messaging.
// https://firebase.google.com/docs/cloud-messaging/admin/send-messages
// https://github.com/firebase/functions-samples/blob/master/fcm-notifications/functions/index.js
//
admin.messaging().sendToDevice(request.query.tokenId, payload).then(response => {
response.results.forEach((result, index) => {
const error = result.error
if (error) {
console.log("Failure sending notification.")
}
});
});
You need to integrate FCM into your iOS app. Pay attention to the part about receiving the current registration token.
Registration tokens are delivered via the FIRMessagingDelegate method
messaging:didReceiveRegistrationToken:. This method is called
generally once per app start with an FCM token. When this method is
called, it is the ideal time to:
If the registration token is new, send it to your application server (it's recommended to implement server logic to determine whether the
token is new).
Subscribe the registration token to topics. This is required only for new subscriptions or for situations where the user has
re-installed the app.
So, you'll have to get a hold of this token in your app, store it somewhere that the Cloud Function can get a hold of (traditionally, Realtime Database), and query for it at the time the function runs.

How to post to a webchat using direct line in Microsoft Bot Service?

In the test web chat in azure portal, I get the bot to speak back to me the conversation id by getting it from session.message.address.conversation.id.
I wish to then view activities for this conversation id using the method described here:
https://learn.microsoft.com/en-us/bot-framework/rest-api/bot-framework-rest-direct-line-3-0-send-activity
(POST https://directline.botframework.com/v3/directline/conversations/abc123/activities
)
However, I get the following error:
{
"error": {
"code": "BadArgument",
"message": "Unknown conversation"
}
}
I have also tried:
POST https://webchat.botframework.com/v3/directline/conversations/9323c31ab1ba42328edc9191621f9c9c/activities
Any help on how I can use direct line to post/view activities for a webchat?
Thanks!
Explain your issue
I cannot reproduce your issue with POST conversations. Actually, I can only reproduce your issue with following step:
generate directline token => leverage the response conversationId and token directly call Retrieve activities with HTTP GET with:
GET https://directline.botframework.com/v3/directline/conversations/abc123/activities
Authorization: Bearer token
The correct steps are:
generate token => POST to Start a conversation => GET to Retrieve activities with HTTP GET.
For your requirement
I don't think we can interrupt outside of the conversion, as the description of Generate a Direct Line token
To generate a Direct Line token that can be used to access a single conversation.
So the token you asked from anywhere else, cannot request the activities in webchat.
An work around
You can leverage BotFramework-WebChat to quickly build up a web site bot testing environment. And generate the token in your own server for the bot client authentication. Then you can use the generated token and conversationId for requesting all the activites between bot and this bot client web site outside of the box.

Facebook messenger, testing chatbot, incorrect sender.id (data.pageEntry.messaging.event.sender.id)

Clarifying my post:
I'm setting up a facebook chatbot using the sample code. This should allow me to send messages to the chatbot (via Messenger iOS app, or via chat window at Facebook.com, app page). The expected behavior would be
Send chat message
Echo chat message
Display correct logging, no errors
However, when I send a chat message, while it correctly echoes the chat message, I am finding an error in my logging. It produces the following error message:
{ message: '(#100) No matching user found',
type: 'OAuthException',
code: 100,
fbtrace_id: 'D+PAc3ZfmLS' }
After investigation, it appears as though the app is identifying the incorrect userID for my account (app owner). It has the correct receiver ID (page ID of the application). I cannot figure out why this occurs. A copy of typical logging information is below. The incorrect sender ID is listed as "1053426944750274".
Received message for user 1053426944750274 and page 289085874757891 at 2016-07-06T20:32:31+00:00 with message: {"mid":"mid.1467837151667:954f158fd950334f60", "seq":212, "text":"marco"}
Successfully sent generic message with id mid.1467837152021:729cf052bc826dc592 to recipient 1053426944750274
Received message for user 289085874757891 and page 1053426944750274 at 2016-07-06T20:32:32+00:00 with message: {"is_echo":true,"app_id":284007785268790, "mid":"mid.1467837152021:729cf052bc826dc592", "seq":213, "text":"marco"}
Are you sure you are using the sender.id in the message recipient.id?
be aware that Facebook id is different than what you need to use when you respond to users via messenger send API.
When representing a user, these IDs are page-scoped IDs (PSID). This means that the IDs of users are unique for a given page.
If you have an existing Facebook Login integration, user IDs are app-scoped and will not work with the Messenger platform.
source

Resources