Linked Questions

Popular Questions

How to build proposed order with what the user has selected?

Asked by At

I'm building an AOG (actions on google) project that will do basic transaction functionality. Since I'm still a bit new to AOG, I'm completely stuck on how to take what the user selects (whether it be a carousel, a basic card etc.) and pass that argument value/key that they selected into the proposed order or the order preview before they finish their transaction.

Here is basically what I have tried (This isn't the actual code because it's rather long, but it still gets the idea across)

    app.intent('delivery_address_complete', (conv) => {
       const arg = conv.arguments.get('DELIVERY_ADDRESS_VALUE');
       if (arg.userDecision ==='ACCEPTED') {
           conv.ask('Ok, what would you like to order?');
           conv.ask(new Suggestions(intentSuggestions));
           conv.ask(new Carousel({
               items: {
              // Add the first item to the carousel
                  SELECTION_KEY_COFFEE: {
                      synonyms: [
                          'Coffee'
                      ],
                      title: 'Coffee',
                      description: 'Sweet cream and sugar coffee.',
                      image: new Image({
                          url: IMG_URL_COFFEE,
                          alt: 'Image alternate text',
                      }),
              },
         }));

     }
    });


    const yesOrno = [
    'Yes',
    'No'
    ];

    app.intent('actions.intent.OPTION', (conv ) => {
        conv.ask('Okay, are you ready to proceed?');
        conv.ask(new Suggestions(yesOrno));
      });


    app.intent('transaction_decision_action', (conv) => {
      const order = {
       id: UNIQUE_ORDER_ID,
       cart: {
          merchant: {
             id: 'coffee',
        name: 'Coffee Store',
         },
           lineItems: [
           {
              name: 'My Memoirs',
              id: 'coffee_1',
          price: {
            amount: {
                 currencyCode: 'USD',
                 nanos: 990000000,
                 units: 3,
            },
            type: 'ACTUAL',
          },
          quantity: 1,
          subLines: [
            {
              note: 'coffee',
            },
          ],
          type: 'REGULAR',
        },

       otherItems: [
      {
        name: 'Subtotal',
        id: 'subtotal',
        price: {
          amount: {
            currencyCode: 'USD',
            nanos: 220000000,
            units: 32,
          },
          type: 'ESTIMATE',
        },
        type: 'SUBTOTAL',
      },
      {
        name: 'Tax',
        id: 'tax',
        price: {
          amount: {
            currencyCode: 'USD',
            nanos: 780000000,
            units: 2,
          },
          type: 'ESTIMATE',
        },
        type: 'TAX',
      },
    ],
    totalPrice: {
      amount: {
        currencyCode: 'USD',
        nanos: 0,
        units: 35,
      },
      type: 'ESTIMATE',
    },
  };

Please note: This is mostly dummy code, so if some things like over charging or prices not making sense is happening, it's not the problem I'm trying to fix.

How can I take what the user selected from whatever method, and get it so it will appear on the order preview or proposed order? I do not need help with anything regarding making carousels or basic cards ect. Just how to get this selected information to the order preview.

To be more specific:

  • I can create an order object that is required, and I know how to send it to Google (and then to the user) as part of a ProposedOrder object that becomes part of the TransactionDecision object. (The "transaction_decision_action" Intent handler in the code above.)
  • What I don't understand is how to build the order based on the user saying things or by selecting on carousel or list items that I've shown them. (What do I do in the "actions.intent.OPTION" Intent handler above, for example?)

edit: This also may clear up any confusion. This is a video representation of what I'm attempting to do (mentioned in comments below):

  • youtube.com/watch?v=LlgMcJBnNN8 from 1:02 to 1:29 I know how to do, I'm confused (In the video example) how they were able to get the 'turkey sandwich' and the 'Green smoothie' added to the order preview at 1:35 ish from the carousel selections

Related Questions