1
votes

probably the most basic question, but the docs (?) suck. I want to send a basic text response from an agent. something like:

router.post('/api/webhook', async (request, response) => {
  const agent = new WebhookClient({ request, response })
  agent.add('hello world')

  // now how do i tell dialogflow to handle the response? none of these work:
  response.send(agent)
  agent.resolve()

this pretty dumb code seemed to work but now has problems

  let intentMap = new Map()
  intentMap.set('reply', () => {
    agent.add('hello world')
  })
  agent.intent = 'reply'
  agent.handleRequest(intentMap)

I don't want to use the intentMap.set or ideally agent.handleRequest(intentMap) And I certainly don't want to use google cloud funcs, plain express is fine.

can't really find any docs that aren't shoving google cloud functions down your throat.

answer: https://blog.dialogflow.com/post/fulfillment-library-beta/

  function intentHandler(agent) {
    agent.add('This message is from Dialogflow\'s Cloud Functions for Firebase editor!');
    agent.add(new Card({
        title: 'Title: this is a card title',
        imageUrl: 'https://developers.google.com/actions/assistant.png',
        text: 'This is the body text of a card.  You can even use line\n  breaks and emoji! ????',
        buttonText: 'This is a button',
        buttonUrl: 'https://assistant.google.com/'
      })
    );
    agent.add(new Suggestion('Quick Reply'));
    agent.add(new Suggestion('Suggestion'));
  }

  agent.handleRequest(intentHandler);

1
Are you suggesting this is both the question and answer? Or are you seeking an answer to your question? It isn't clear exactly what you're trying to get, particularly since you posted an "answer" below that just repeats the last part of your question. - Prisoner
I found an answer after asking the question and posted in case someone else was puzzled. I'll clarify that. - dcsan

1 Answers

1
votes

I found one way of doing it which is not too verbose, posting in case anyone finds this

Note it's important to also remove replies for Default Fallback from your GUI code in DF

  function intentHandler(agent) {
    agent.add('Hello World');
  }

  agent.handleRequest(intentHandler);