3

I want to create a chatbot with Dialogflow and Google Assistant along with Google Transactions API for enabling a user to order some items. For now my agent contains the following four intents:

  • Default Welcome Intent (text response: Hello, do you want to buy a chocolate box?)
  • Default Fallback Intent
  • Int3 (training phrase: Yes, I want, fulfilment: enabled webhook)
  • Int4 (event: actions_intent_TRANSACTION_DECISION, fulfilment: enabled webhook)

I am using Dialogflow Json instead of Node.js to connect my agent with Transactions API. I want to build a cart and an order for the user by using finally that the user meets the transaction requirements by using the actions.intent.TRANSACTION_DECISION action of Google actions. For this reason, following Google docs, when Int3 is triggered I am using a webhook which connect Google Assistant my back-end which sends back the following json to trigger actions.intent.TRANSACTION_DECISION.

As a result, the preview of the order is presented to the user on Google Assistant (on mobile phone). However, the delivery address details are not presented on this order preview as at the photo below.

Let me note that I have already gone to Google Assistant app -> Settings -> Payments and there I filled in my address details. As a result, when I trigger the actions.intent.DELIVERY_ADDRESS intent then as expected I get the delivery address of Google Assistant app -> Settings -> Payments as this is shown at this image: Image. Therefore, it is not that I anticipated that my delivery address will appear on the order preview out of nowhere without having set it first of all.

I have the impression that this can be done by adding the extension object to the whole structure of ProposedOrder object which is the following:

{   "id": string,   
"cart": {
        object(Cart)   },  
 "otherItems": [
        {
          object(LineItem)
        }   ],   "image": {
        object(Image)   },   
"termsOfServiceUrl": string,   
"totalPrice": {
        object(Price)   },   
"extension": {
        "@type": string,
        field1: ...,
        ...   } }

So the whole json response through my webhook to trigger actions.intent.TRANSACTION_DECISION is the following:

{
    "fulfillmentText": "This is your order preview:",
    "payload": {
        "google": {
            "expectUserResponse": true,
            "isSsml": false,
            "noInputPrompts": [],
            "systemIntent": {
                "data": {
                    "@type": "type.googleapis.com/google.actions.v2.TransactionDecisionValueSpec",
                    "orderOptions": {
                        "requestDeliveryAddress": true
                    },
                    "paymentOptions": {
                        "actionProvidedOptions": {
                            "displayName": "VISA **** **** **** 3235",
                            "paymentType": "PAYMENT_CARD"
                        }
                    },
                    "proposedOrder": {
                        "cart": {
                            "lineItems": [
                                {
                                    "description": "Book",
                                    "id": "1",
                                    "name": "Book",
                                    "price": {
                                        "amount": {
                                            "currencyCode": "USD",
                                            "nanos": 0,
                                            "units": 31
                                        },
                                        "type": "ACTUAL"
                                    },
                                    "quantity": 2,
                                    "subLines": [],
                                    "type": "REGULAR"
                                }
                            ],
                            "merchant": {
                                "id": "Amazon",
                                "name": "Amazon"
                            },
                            "otherItems": []
                        },
                        "extension": {
                            "@type": "type.googleapis.com/google.actions.v2.orders.GenericExtension",
                            "locations": [
                                {
                                    "location": {
                                        "phoneNumber": "123456789",
                                        "postalAddress": {
                                            "recipients": [
                                                "Me"
                                            ],
                                            "regionCode": "USA"
                                        }
                                    },
                                    "type": "DELIVERY"
                                }
                            ]
                        },
                        "id": "<UNIQUE_ORDER_ID>",
                        "otherItems": [],
                        "totalPrice": {
                            "amount": {
                                "currencyCode": "USD",
                                "units": 31
                            },
                            "type": "ACTUAL"
                        }
                    }
                },
                "intent": "actions.intent.TRANSACTION_DECISION"
            }
        }
    }
}

but then I am getting this error on the Google Assistant simulator:

Sorry, something went wrong. Please try again later.

So I cannot really understand if I am not doing something right regarding the type and the format of the extension object.

The logs at Google Assistant in this case are the following:

2018-05-23 09:12:47.024 BST
Received response from agent with body: HTTP/1.1 200 OK Server: nginx/1.13.6 Date: Wed, 23 May 2018 08:12:46 GMT Content-Type: application/json;charset=UTF-8 Content-Length: 1782 X-Cloud-Trace-Context: **************************/**************************;o=1 Google-Actions-API-Version: 2 Via: 1.1 google Alt-Svc: clear {"conversationToken":"[\"more\"]","expectUserResponse":true,"expectedInputs":[{"inputPrompt":{"richInitialPrompt":{"items":[{"simpleResponse":{"textToSpeech":"This is your order preview:"}}]}},"possibleIntents":[{"intent":"actions.intent.TRANSACTION_DECISION","inputValueData":{"orderOptions":{"requestDeliveryAddress":true},"paymentOptions":{"actionProvidedOptions":{"displayName":"VISA **** **** **** 3235","paymentType":"PAYMENT_CARD"}},"@type":"type.googleapis.com/google.actions.v2.TransactionDecisionValueSpec","proposedOrder":{"extension":{"@type":"type.googleapis.com/google.actions.v2.orders.GenericExtension","locations":[{"location":{"phoneNumber":"123456789","postalAddress":{"regionCode":"USA","recipients":["Me"]}},"type":"DELIVERY"}]},"totalPrice":{"amount":{"nanos":0.0,"units":36.0,"currencyCode":"USD"},"type":"ACTUAL"},"id":"<UNIQUE_ORDER_ID>","otherItems":[{"price":{"amount":{"nanos":0.0,"units":31.0,"currencyCode":"USD"},"type":"ACTUAL"},"name":"Subtotal","id":"Subtotal","type":"SUBTOTAL"},{"price":{"amount":{"nanos":0.0,"units":5.0,"currencyCode":"USD"},"type":"ACTUAL"},"name":"Delivery fees","id":"Delivery fees","type":"FEE"}],"cart":{"lineItems":[{"quantity":2.0,"price":{"amount":{"nanos":0.0,"units":31.0,"currencyCode":"USD"},"type":"ACTUAL"},"name":"Book","description":"Book","id":"1","type":"REGULAR"}], "merchant":{"name":"Amazon","id":"Amazon"},"otherItems":[]}}}}],"speechBiasingHints":["$polar","$products"]}],"responseMetadata":{"status":{"message":"Success (200)"},"queryMatchInfo":{"queryMatched":true,"intent":"df9de4fe-fc2a-4735-a45e-f1688da93201","parameterNames":["polar"]}}}.
Expand all | Collapse all {
 insertId:  "**************************"  
 labels: {…}  
 logName:  "**************************/logs/actions.googleapis.com%2Factions"  
 receiveTimestamp:  "2018-05-23T08:12:47.035898145Z"  
 resource: {…}  
 severity:  "DEBUG"  
 textPayload:  "Received response from agent with body: HTTP/1.1 200 OK
Server: nginx/1.13.6
Date: Wed, 23 May 2018 08:12:46 GMT
Content-Type: application/json;charset=UTF-8
Content-Length: 1782
X-Cloud-Trace-Context: **************************/**************************;o=1
Google-Actions-API-Version: 2
Via: 1.1 google
Alt-Svc: clear

{"conversationToken":"[\"more\"]","expectUserResponse":true,"expectedInputs":[{"inputPrompt":{"richInitialPrompt":{"items":[{"simpleResponse":{"textToSpeech":"This is your order preview:"}}]}},"possibleIntents":[{"intent":"actions.intent.TRANSACTION_DECISION","inputValueData":{"orderOptions":{"requestDeliveryAddress":true},"paymentOptions":{"actionProvidedOptions":{"displayName":"VISA **** **** **** 3235","paymentType":"PAYMENT_CARD"}},"@type":"type.googleapis.com/google.actions.v2.TransactionDecisionValueSpec","proposedOrder":{"extension":{"@type":"type.googleapis.com/google.actions.v2.orders.GenericExtension","locations":[{"location":{"phoneNumber":"123456789","postalAddress":{"regionCode":"USA","recipients":["Me"]}},"type":"DELIVERY"}]},"totalPrice":{"amount":{"nanos":0.0,"units":36.0,"currencyCode":"USD"},"type":"ACTUAL"},"id":"<UNIQUE_ORDER_ID>","otherItems":[{"price":{"amount":{"nanos":0.0,"units":31.0,"currencyCode":"USD"},"type":"ACTUAL"},"name":"Subtotal","id":"Subtotal","type":"SUBTOTAL"},{"price":{"amount":{"nanos":0.0,"units":5.0,"currencyCode":"USD"},"type":"ACTUAL"},"name":"Delivery fees","id":"Delivery fees","type":"FEE"}],"cart":{"lineItems":[{"quantity":2.0,"price":{"amount":{"nanos":0.0,"units":31.0,"currencyCode":"USD"},"type":"ACTUAL"},"name":"Book","description":"Book","id":"1","type":"REGULAR"}],"merchant":{"name":"Amazon","id":"Amazon"},"otherItems":[]}}}}],"speechBiasingHints":["$polar","$products"]}],"responseMetadata":{"status":{"message":"Success (200)"},"queryMatchInfo":{"queryMatched":true,"intent":"df9de4fe-fc2a-4735-a45e-f1688da93201","parameterNames":["polar"]}}}."  
 timestamp:  "2018-05-23T08:12:47.024908542Z"  
 trace:  "**************************"  
}

How to add the delivery address details to the order preview?

This is an example of an order preview from Google docs which includes delivery address details: enter image description here

P.S. The object(Cart) contains the "notes": string which can add a section at the final order preview exactly where the Delivery address section is placed at the order preview at the photo above. Therefore, I can add

"notes": "Lola\n1950 Charleston Road\nMountain View, CA 94043\n415 789 8934"

or my personal address details to the object(Cart) and then I can display the delivery details to the final order preview as it is shown at this image: Image.

However in this way the title of this section at the order preview is Notes while I want obviously Delivery address as the title as it it shown at the photo above.

Outcast
  • 4,967
  • 5
  • 44
  • 99

1 Answers1

2

Based on the error you're getting, it looks like the URI value for @type is incorrect.

Since you're already building a ProposedObject, you will need to use a @type: type.googleapis.com/google.actions.v2.orders.GenericExtension inside of the extension field of the ProposedObject (note orders in the URI). Per the docs you mentioned, GenericExtension will have a locations array that will contain an object of type OrderLocation where you can specify the delivery address.

The final JSON for an extension will look like:

"extension": {
    "@type": "type.googleapis.com/google.actions.v2.orders.GenericExtension",
    "locations": [
        {
          type: 'DELIVERY',
          location: {
            "postalAddress": {
            "regionCode": "USA",
            "recipients": [
                "Me"
             ],
            },
           "phoneNumber": "123456789" 
          }
        }
    ]
}

The rest of ProposedOrder fields will be the same as in your example.

Please see an example of using Transactions API in the official sample for more details.

Aza T
  • 589
  • 4
  • 11
  • Thank you for your response. However, I am getting this error when I am using your json: "Sorry, something went wrong. Please try again later.". The json is processed and sent back to Google Assistant ok but after this nothing happens while `TRANSACTION_DECISION` should have been triggered. I have the impression that it has something to do with the fact that I am using the conversation webhook docs while you are referring to the Node.js Client Library Version 1 Migration Guide since you are using the orders class. Any additional idea how to fix this? – Outcast May 21 '18 at 08:47
  • It's hard to know what the issue is without looking at the Conversation Webhook request that you're sending. Can you post it here? I suspect the issue may be with the request you're sending. You can try to troubleshoot it in the Actions simulator - it will show you exactly what request & response you're getting. Additionally, you'll also be able to see the logs. I don't think the issue is with Node.js client library vs. Conversation webhook, since in the docs both have the same ```@type``` values per official docs. https://developers.google.com/actions/reference/rest/conversation-webhook – Aza T May 21 '18 at 17:42
  • Ok, yes, I edited my whole post above and I posted what I did after using your response. By the way, notice that at your json some double quotes are missing at `type` and `location`. Hence, can you understand from my updated post what is going wrong? – Outcast May 22 '18 at 12:50
  • I don't see anything that stands out wrong. Can you check the logs in the simulator? – Aza T May 22 '18 at 23:44
  • I edited my post to include the logs. A fact is that I am getting this error `Sorry, something went wrong. Please try again later.` when using `orders.GenericExtension` while if I use wrong types then I am getting an error which explicitly says that there is no type like this. This makes me think that `orders.GenericExtension` is right but it conflicts with something else at Google Assistant which may be related to permissions etc as it is mentioned at this post: https://stackoverflow.com/questions/49346394/actions-on-google-returns-in-simulator-were-sorry-but-something-went-wrong-p. – Outcast May 23 '18 at 11:57
  • However, can you please elaborate at your post on why you are using `orders.GenericExtension` and not for example `order.GenericExtension` or even `.GenericExtension`? Google docs mention a `order` class so I do not get exactly why you are using `orders` in `orders.GenericExtension`. Also in general Google docs are not really so clear how to handle types and how to format them in your source code after then end of `type.googleapis.com/google.actions.v2.`. – Outcast May 23 '18 at 12:05
  • *after then end of `type.googleapis.com/google.actions.v2.` -> with `type.googleapis.com/google.actions.v2.` – Outcast May 23 '18 at 12:21
  • I used ```orders.GenericExtension``` because this is what is used in the official transaction sample on GitHub (line 29). I strongly recommend checking it out. https://github.com/actions-on-google/dialogflow-transactions-nodejs Though, this sample uses client library, you can still extract useful debug info. It will give the JSON body of the DialogFlow response that you can cross-match against your custom built JSON. – Aza T May 24 '18 at 05:42
  • Hmm, ok so you have not figured either why `orders.GenericExtension` is used but simply you saw this on the sample project. Actually, I have read through this project but I did not notice that. My impression is now then that `orders.GenericExtension` is for node.js client but not for the conversation webhook so finally your solution does not seem to be right. I would really appreciate if you have a look at Google docs to tell me your opinion about how to implement this with the conversation webhook (since Google docs look quite obscure at this part). :) – Outcast May 24 '18 at 09:07