Edit request in js before sending it to fullfillment endpoint - dialogflow-es

I need to edit request before sending it to endpoint.
Using Web Demo integration I'm able to send request to the endpoint.
But I can't edit the request in order to provide some extra data to request. Extra data is stored in localStorage so I need to do this in javascript.
I've already connected the agent to an endpoint that handle the request using fullfillment. The problem is that request misses data I can retrieve only from the browser. From fullfillment I can set headers and basic auth but statically and it is not enough.
So I need to add a step in request building/sending:
User write or tell something to embedded chat (Web Demo integration)
Dialogflow recognize intent, params, generate the request.
Additional step: Update the request in javascript
Forward cutomized request to the endpoint
Maybe it's not possible using Web Demo integration. In Documentation can't find a way to just send string or audio in order to receive the generated request.

First of all you will need a custom chat integration, not the default Dialogflow one. Something like Smooch or Kommunicate. The default web demo should only be used for testing your bot. There is NO way you would want to use that in a production environment.
I would save whatever is in the local storage in a database such as Firestore. Once that data is in the database you can use it to modify your request in your fulfillment.
So what I would do:
Have a way to identify a user and save its local storage to the database (as soon as someone clicks on your chat window or opens the chat window)
Once an intent is triggered you check which user is contacting you (through the way that you identified the user) and get all data from the database
Request the data in your fulfillment server
There is no other way in which this is possible. You can't change requests before your query hits Dialogflow.

Related

How to get and pass user conversation data to backend API in Azure Bot Framework Composer v1.4.0?

I am new to Azure Bot Framework Composer.
I am creating chatbot using Azure Bot Framework Composer(without writing code) which need to be launch in Angular Web Application from Azure Cloud after deployment.
In my chatbot project, need to fetch the user conversation data and send it to backend API from Azure Bot Framework Composer.
How to achieve this?, anyone help on this.
You can view the conversation data using ${conversation} scope and from dialog stack can access required information. To get last conversation data can use ${turn.Activity}. For sending to backend API, create HTTP post method and pass the data in the body of your request.
Without knowing more details on your chatbot project, one reasonable approach to take is to use the Send HTTP Request action in the composer.
After you obtain the values from the conversation that you are looking for, (can be stored in conversation / dialog variables), you could then pass it onto an HTTP send request and deliver that to your backend API.
With this, you can send any payload to your backend API.

How do i authenticate my api (node app) when being accessed by my UI?

I've looked at various approaches to this but I'm yet to find one that is perfect for my set up.
I have a UI that calls the api to present data to a user - the UI doesn't require someone to login and i don't want to authenticate every user. What i'm trying to do is simply protect the api because with the url to the api, anyone will be able to access the data.
In my mind, i can create a password/ apikey of some sort and store that as an environment variable that is sent from the UI to the API whenever a request is made. On the API, that apikey/password is validated before allowing access to the api.
Does this sound wise? Would you suggest something else? Have i missed anything. All thoughts are welcome.
The solution sounds good to me. You can do something like this:
back-end: create a new REST endpoint (something like /api/get-token) in your Node.JS application which generates a token (or ID), saves it locally (maybe into a DBMS) and returns it as response. Then, in every endpoint you need to protect, you extract the token from the request and, before sending any "private" data, you check if the supplied token is valid, or not.
front-end: as soon as your application is loaded, you send a request to the newly created REST endpoint and store the given token locally (localStorage should be fine). Then, every time the UI needs to access "private" data, you simply supply the claim within the request.
The implementation should be pretty straight forward.

get JSON generated by a webhook hosted onlilne

I am making a plagariam check and then it communicates to the server of the company via webhook, the response is then recorded in RequestBin, which generates a JSON response in their website, how do I extract the information from the website to my node js code?
The webpage looks like this: my requestb.in online webhook
What I need is to get that raw JSON.
You cannot get data via API from RequestBin.
RequestBin doesn't provide API for you to catch the responses. It is built for manual testing where a person checks the data using their UI.
If you wish to check the response, register a WebHook with the company that points to your server where your app resides.

How do I send a user to a URL with push notification

I use Microsoft's appcenter for my applications and want to send out a notification to all of my users containing custom data to push them to a URL.
I've tried looking at the documentation and can't seem to figure it out...
How do I do this via appcenter's UI?
Cheers.
Send the URL in a custom data object included with your notification, you can see an example of custom data here: https://learn.microsoft.com/en-us/appcenter/push/send-notification#compose. In the client application, pull the custom data object off the notification, grab the URL and do whatever you want to do with it.

Sending Firebase Notification with nodejs

I have an android app on which I want to send notification via my web app.
How do I send Firebase Cloud Messaging notification with nodejs? I have found a lot of examples and posts on this subject, but in all of them you are supposed to just paste device Token and send notification to that device. If I wanted to use it that way, I would be able to simply implement this from official documentation.
The thing is, I need to receive user id from database so I know which user I want to send notification. After I have user id I can then retrieve device Token from the same database. I get both user id and device token on client side. And documentation refers to server side.
This all happen after button click. So, I don't understand how to send notification on server side, meaning, I don't have there all those informations I need - user id, device token and message info that contain some other database info. Do I pass those arguments from client side to server side somehow, or is there a way of using modules like "require()" on client side?
What is the best approach here?
You will need to implement a device token registry to fit with your use case. So if you want to send messages to users, then you will need a registry (really just a fancy word for a database) of the token(s) for each user. Then when you want to send a specific user a message, you look up their token(s) in the registry, and call the FCM API to send messages to them. Since you mention Node.js, you can likely do this using the Firebase Admin SDK: https://firebase.google.com/docs/cloud-messaging/admin/send-messages#send_to_individual_devices.
An alternative I have once written article about using a topic for each user, which saves having to have a registry of their tokens. While this is less secure (since anyone who knows a topic, can subscribe to it), it is definitely easier to implement.

Resources