keeb117
keeb117

Reputation: 53

Trigger a Dialogflow intent on button click in Google chat

I am trying to trigger a Dialogflow intent with a button click (located in a card) in Google chat. I am currently using the Dialogflow console's fulfillment section to do this.

Here is an generic example of what I have for code:

// This intent is triggered on Google chat with end user typing: "hi"
function first_Intent(agent) {
  agent.add('FIRST INTENT TRIGGERED');
  addHangoutsCustomPayload(agent, buildCustomPayload()); 
}

// This is the intent I am trying to call from the onClick in the payload
function second_Intent(agent) {
  agent.add('SECOND INTENT TRIGGERED');
}

// Helper function that added hangouts prop to payload
function addHangoutsCustomPayload(agent, cardJSON) {
  const payload = new Payload(
      'hangouts', cardJSON, {rawPayload: true, sendAsMessage: true});
  agent.add(payload);
}

// Function that builds custom payload 
function buildCustomPayload() {
  let customPayload = {
    'hangouts': {
      'header': {
        'title': 'GENERIC CARD TITLE',
        'subtitle': 'GENERIC CARD SUBTITLE',
        'imageUrl':
            'GENERIC-CARD-PNG'
      },
      'sections': [{
        'widgets': [{
          'buttons': [
            {
              'textButton': {
                'text': 'CALL OTHER INTENT',
                'onClick': {
                  // TODO: call second_Intent from here
                  'action': {
                          'actionMethodName': 'second_Intent',
                          'parameters': []
                  }
                }
              }
            }
          ]
        }]
      }]
    }
  };
  return customPayload;
}

let intentMap = new Map();
intentMap.set('First Intent', first_Intent);
intentMap.set('Second Intent', second_Intent);

As you can see from the code, I am attempting to call the second_Intent function from the button click in the payload (commented in the payload code).

When I try to click the button in the Google chat window (titled: CALL OTHER INTENT, in this case), Google chat shows a brief loading/progress bar under the card and then doesn't do anything.

I have tried doing actionMethodName in the card, but it doesn't work. Has anyone else tried to do something like this?

Upvotes: 0

Views: 35

Answers (0)

Related Questions