0.1.0 • Published 4 years ago

ck-dialogflow-webhook v0.1.0

Weekly downloads
2
License
Apache-2.0
Repository
github
Last release
4 years ago

Dialogflow webhook –  mechanism for alerting you to system events through callbacks.
You can use this webhook with CK Dialogflow module.

:space_invader: Install

For install library you need enter next comand:

npm i ck-dialogflow-webhook

Usage

import * as express from 'express'

import ckDialogflowWebhook from 'ck-webhook-dialogflow'
const configPath = <Path to your private key file>
const dialogflow = ckDialogflowWebhook(configPath)

const app = express()

app.use(dialogflow)

You need to set up authentication. The client application that uses the API must be authenticated and granted access to the requested resources. You need create a service account and download the private key file (token). Instruction about this you can reed here (title "Set up authentication")

Routes

/ckWebhook/dialogFLow/chatInit

router.post('/ckWebhook/dialogFLow/chatInit', (req, res) => {
  const { sessionId, projectId } = req.body.data
  try {
    const sessionPath = sessionClient.sessionPath(projectId, sessionId)

    const result = {
      sessionPath,
    }
    res.json({ result })
  } catch (err) {
    console.log(err)
  }
})

/ckWebhook/dialogFLow/chatRequest

router.post('/ckWebhook/dialogFLow/chatRequest', async (req, res) => {
  try {
    const { data } = req.body
    const result = await chatRequset(sessionClient, data)
    res.json({ result })
  } catch (err) {
    console.log(err)
  }
})

/ckWebhook/dialogFLow/chatEvent

router.post('/ckWebhook/dialogFLow/chatEvent', async (req, res) => {
  try {
    const { data } = req.body
    const result = await chatEvent(sessionClient, data)
    res.json({ result })
  } catch (err) {
    console.log(err)
  }
})