0

I'm trying to process the response data in the open dialog but got stuck in this the retrieval.
I followed the step by step procedure given in this link: https://developers.google.com/chat/how-tos/dialogs but unfortunately, it didn't work as well.

Here is the sample code:

My goal is to get the data from the dialog form then process it. My pain point is in the code: event.common.formInputs.firstnumber.stringInputs.value[0] where it returns undefined reading value.

function openDialog(event) {
  return {
    "action_response": {
        "type": "DIALOG",
        "dialog_action": {
          "dialog": {
            "body": {
              "sections": [
                {
                  "header": "Addition Calculator:",
                  "widgets": [
                    {
                  "textInput": {
                    "label": "First Number",
                    "type": "SINGLE_LINE",
                    "name": "firstnumber"
                  }
                },
                {
                  "textInput": {
                    "label": "Second Number",
                    "type": "SINGLE_LINE",
                    "name": "secondnumber"
                  }
                },
                {
                  "textInput": {
                    "label": "Third Number",
                    "type": "SINGLE_LINE",
                    "name": "thirdnumber"
                  }
                },
                {
                      "buttonList": {
                        "buttons": [
                          {
                            "text": "Submit",
                            "onClick": {
                              "action": {
                                "function": "giveAnswer"
                              }
                            }
                          }
                        ]
                      },
                      "horizontalAlignment": "END"
                    }
                  ]
                }
              ]
            }
          }
        }
    }
  };
}


function giveAnswer(event) {
  var firstterm = parseFloat(event.common.formInputs.firstnumber.stringInputs.value[0])
  var secondterm = parseFloat(event.common.formInputs.secondnumber.stringInputs.value[0])
  var thirdterm = parseFloat(event.common.formInputs.thirdnumber.stringInputs.value[0])
  var sum = firstterm+secondterm+thirdterm
  return {
      "cardsV2": [{
        "cardId": "addContact",
        "card": {
          "header": {
            "title": "The SUM is:",
            "subtitle": "Answer",
            "imageUrl": "https://images.emojiterra.com/google/noto-emoji/v2.034/128px/1f4f1.png",
            "imageType": "SQUARE"
          },
          "sections": [
            {
              "widgets": [
                {
                  "textParagraph": {
                        "text": sum
                      }
                    }
                  ]
                }
              ]
            }
          }
        ]
      }
    }

I tried the example in here but didn't work as well. https://developers.google.com/chat/how-tos/dialogs#receive_form_data_from_dialogs

Rubén
  • 34,714
  • 9
  • 70
  • 166
youricast
  • 1
  • 2

0 Answers0