Is there a way to retrieve the conversation history in Dialogflow? - node.js

Is there a way to obtain the full conversation between the user and agent. Pretty much similar to what I get by clicking the history tag but programmatically. The point is to save the interaction between user and agent as text.
Thank you guys in advanced!

There's no API to retrieve the history from Dialogflow directly. But what you can do is enable logging.
Agent Settings > General > Log Settings > Log interactions to Google Cloud
And all the interactions will be logged into Google Stackdriver, which has an API where you will be able to retrieve all the logs, and hence the chat history.
https://cloud.google.com/logging/docs/reference/v2/rest/
This is how the logs are stored in Stackdriver
{
insertId: "19ignahfzlu2o7"
labels: {
protocol: "V2BETA1"
request_id: "3033c2e3-7cab-4a00-b2b7-207be8d22366"
type: "dialogflow_request"
}
logName: "projects/dialogflowproject-ca57b/logs/dialogflow_agent"
receiveTimestamp: "2019-03-27T12:44:42.547531753Z"
resource: {
labels: {
project_id: "dialogflowproject-ca57b"
}
type: "global"
}
severity: "INFO"
textPayload: "Dialogflow gRPC Request : session: projects / dialogflowproject - ca57b / agent / sessions / 53 d451c1 - 40 f5 - c00e - cbbd - 178e ff32b971 "
query_params {
time_zone: "America/Buenos_Aires"
}
query_input {
text {
text: "hi"
language_code: "en"
}
}
"
timestamp: "2019-03-27T12:44:42.420Z"
trace: "53d451c1-40f5-c00e-cbbd-178eff32b971"
}
You can then retrieve the session from there, and build the whole chat history.
The other alternative is to save the interactions to a database when they are happening if the messages goes through your server first, which may not be your case.

Related

How to set dialogflow fulfillment response json context without using webhook client?

I want to create a rich response to Facebook integration using Dialogflow fulfillment. I tried using webhook but it's not working and then I try below way directly using response and now I am facing this context binding issue.
I tried below
let responseJson = {};
let rich = [
{
'text': {
'text': [
text
],
},
'platform': 'FACEBOOK'
},
];
responseJson.fulfillmentMessages = rich;
responseJson.outputContexts = context;
response.json(responseJson);
my context JSON
{ name: 'MAINTENANCE_REQUEST', lifespan: 5, parameters: { maintenanceRequest: maintenanceRequest }}
To add a custom payload without a webhook, go to your intent, and scroll to the bottom where it says "responses". Click on the plus sign (picture) and click on the facebook option. Click on the add responses -> custom payload. The format and available fields for the custom payload are described here. Delete the "Text Response" if it's there so the custom payload will be the only one to be returned.

How to use Pinpoint to send a text message from a long code in python?

I am currently using boto3 to send text messages to my audience. The problem is that the text message always comes from a short code regardless of whether I put one of my valid long codes in the OriginationNumber field.
client.send_messages(
ApplicationId='appID',
MessageRequest={
'Context': {},
'Addresses': {
event['phone_number']: {
"ChannelType": "SMS"
}
},
'MessageConfiguration': {
'SMSMessage': {
'Body': 'hello world',
'OriginationNumber': "+15405551234",
'MessageType': 'TRANSACTIONAL'
}
}
}
)
If anyone else runs into this. I have to open a support ticket with aws and provide them with a use case describing my application. So, sign-in into the console and head to the support section.

Send back rich responses to Actions on Google through Dialogflow webhook fulfillment

To get Google Assistant to display rich responses to the user, one must provide it with a response like the example on the Actions on Google docs. However, since I'm using Dialogflow as the intermediary party between my server and Google's, I need to provide some kind of response to Dialogflow in my webhooks to indicate that there should be a rich response. As you can see from that link, the docs mention how to send rich responses to FB Messenger, Kik, LINE, etc. but not Google Assistant.
What am I missing here? I see an option for rich responses in the Dialogflow web console, but there I can only seem to input hardcoded responses with no dynamic data from the server. What's the right way to do this?
Using the Dialogflow integration, the response JSON your webhook should return for a rich response will look like:
{
"data":{
"google":{
"expectUserResponse":true,
"noInputPrompts":[
],
"richResponse":{
"items":[
{
"simpleResponse":{
"textToSpeech":"Welcome to this Basic Card",
"displayText":"Welcome to this Basic Card"
}
},
{
"basicCard":{
"buttons":[
{
"title":"Button Title",
"openUrlAction":{
"url":"https://some.url"
}
}
],
"formattedText":"Some text",
"image":{
"url":"http://some_image.jpg",
"accessibilityText":"Accessibility text describing the image"
},
"title":"Card Title"
}
}
],
"suggestions":[
{
"title":"Aléatoire"
},
{
"title":"Top"
}
]
}
}
}
}
If you are using the Node.js library You can also use the provided methods for Dialogflow integration to build your rich response.
If you're using Node.js you should call the method buildRichResponse() and then add items as child of that object, like this:
app.ask(app.buildRichResponse()
.addSimpleResponse('A text to be spoken')
.addBasicCard(app.buildBasicCard('Some text to be displayed')
.setTitle('A title')
.addButton('Read more', 'https://example.google.com/something')
.setImage('https://example.google.com/image.png', 'Image alternate text')
.setImageDisplay('CROPPED')
)
);
That was an example for adding a BasicCard, you can see how to add Carousels, Lists and Suggestions Chips at https://developers.google.com/actions/assistant/responses#rich-responses

Chrome DevTools Protocol: control new tabs

Need to be done: I need to simulate user interactions (journeys) across a chain of sites.
Question: Do you have any tips how to programatically controll a tab opened as a result of a simulated click?
My experience:
I'm using the chrome-remote-interface npm package.
I'm able to simulate a click with a custom ChromeController class which initializes the chrome-remote-interface and these methods:
async simulateClick(selector) {
return await this.evaluate(function (selector) {
document.querySelector(selector).click()
}, selector);
}
/**
* Shamelessly stolen from simple-headless-browser
*/
async evaluate (fn, ...args) {
const exp = args && args.length > 0 ? `(${String(fn)}).apply(null, ${JSON.stringify(args)})` : `(${String(fn)}).apply(null)`
const result = await this.client.Runtime.evaluate({
expression: exp,
returnByValue: true
})
return result
}
Now I would like to interact with the recently opened tab. I can get the targetId of the new tab with the experimenetal Target Domain (prototyping in node cli):
var targets;
chromeController.client.Target.getTargets().then(t => targets = t);
Which results in:
{ targetInfos:
[ { targetId: '97556479-cdb6-415c-97a1-6efa4e00b281',
type: 'page',
title: 'xxx/preview/239402/',
url: 'xxx/preview/239402/' },
{ targetId: 'bbfe11d5-8e4a-4879-9081-10bb7234209c',
type: 'page',
title: 'Document',
url: 'xxx/preview/239402/teaser/0/' } ] }
I am able to switch between the tabs with:
chromeController.client.Target.activateTarget({targetId:'xxx'})
However I'm not able to get any interaction with this, I can't find the connection, how to load it into the Page and Runtime objects.
I've searched in the docs and also tried googling: 'site:chromedevtools.github.io targetId' which only lead me to
> chromeController.client.Browser.getWindowForTarget({targetId: '97556479-cdb6-415c-97a1-6efa4e00b281'}).catch(e => console.log(e.message));
Promise { <pending> }
> 'Browser.getWindowForTarget' wasn't found
I've also tried to Target.setDiscoverTargets({discover: true}) and to close the original tab.
Thanks for any help!
Recently faced this same issue and in short I had to create a new dev tools protocol client for each new target I wanted control over.
My experience is with dev tools protocol using direct communication with websocket but the api is the same so it should be similar. So here is a summary of what I had to do.
Initially looking at the docs I would have assumed Target.attachToTarget should give us control of the new tab but I found that it didn't work.
My workaround was to create a listener that listened for the Target.targetCreated event which provides a targetInfos just like you found with Target.getTargets but for every new target created like a new tab, page, or iframe. Note: you need to enable Target.setDiscoverTargets in order to receive these events over the protocol.
[ { targetId: '97556479-cdb6-415c-97a1-6efa4e00b281',
type: 'page',
title: 'xxx/preview/239402/',
url: 'xxx/preview/239402/' },
{ targetId: 'bbfe11d5-8e4a-4879-9081-10bb7234209c',
type: 'page',
title: 'Document',
url: 'xxx/preview/239402/teaser/0/' } ] }
With that listener I looked for targets that were of type page, you could filter on a specific url if you know what the page will be. With the targetId in hand I requested available websocket targets following the HTTPEndpoints section near the bottom of the devtools home page.
GET /json or /json/list
A list of all available websocket targets.
[ {
"description": "",
"devtoolsFrontendUrl": "/devtools/inspector.html?ws=localhost:9222/devtools/page/DAB7FB6187B554E10B0BD18821265734",
"id": "DAB7FB6187B554E10B0BD18821265734",
"title": "Yahoo",
"type": "page",
"url": "https://www.yahoo.com/",
"webSocketDebuggerUrl": "ws://localhost:9222/devtools/page/DAB7FB6187B554E10B0BD18821265734"
} ]
I could then launch a new dev tools protocol client using the webSocketDebuggerUrl and have full control over the tab.
I know this is a pretty round about way but, its the only way I was able to make if work.
Although these days it's probably easier to use something like puppeteer to interface with multiple tabs in chrome if you can. Here is the source code to a puppeteer module that follows new tabs that could be good reference for trying to replicate it pageVideoStreamCollector.ts
This is a very late answer but just putting this here if anyone else has the same issue as help on chrome dev tools is very hard to come by. Hope it helps someone out.
I also am getting "Browser.getWindowForTarget wasn't found" on debian, google-chrome-unstable version 61

Using Pubsub to push Gmail in node.js - How to set publish rights?

I'm trying grant publish rights to a topic using SetIamPolicy as has been described here: [Google Cloud Pub/Sub API - Push E-mail but no success yet - not sure what the exact call should look like.
For now I've made a json file containing this:
POST "https://pubsub.googleapis.com/v1beta2/{resource=projects/myproject/topics/mytopic}:setIamPolicy"
Content-type: application/json
{
"policy": {
"bindings": [{
"role": "roles/pubsub.publisher",
"members": ["serviceAccount:gmail-api-push#system.gserviceaccount.com"],
}],
}
}
as described here: http://developers.google.com/gmail/api/guides/push and call it like this: topics.SetIamPolicy('pubsub_policy.json'); - but setiampolicy is an undefined function. Any ideas? Googling has yielded absolutely nothing in terms of examples in node.js
I used the Google Developers Console
After a lot searching I found it was easier to just set the publish rights in the Google Developers Console.
click on your project
click on Big Data > Pub/Sub
If you haven't already done so, create a topic
Check the box next to that topic
Click the permissions button at the top
Add your permissions in the box that should look like this
I did find this documentation about setIamPolicy() for nodejs.
var myPolicy = {
bindings: [
{
role: 'roles/pubsub.subscriber',
members: ['serviceAccount:myotherproject#appspot.gserviceaccount.com']
}
]
};
topic.iam.setPolicy(myPolicy, function(err, policy, apiResponse) {});
subscription.iam.setPolicy(myPolicy, function(err, policy, apiResponse) {});
But I couldn't get it to work. topic.iam.setPolicy() didn't exist. All I saw was this:
//console.log(topic)
{
...
iam: {
resource: 'projects/[projectId]/topics/[topicName]',
makeReq_: [Function] }
}

Resources