Dialogflow

In this tutorial, you will learn how to integrate your instance of Dialogflow ES or CX, so that you can send the audio from the call to the agent and get a response from the bot played on your call.

Dialogflow ES

In order to do successfully integrate Dialogflow ES with Telnyx Voice API, you'll need to start by assigning the Dialogflow configuration to your Call Control application using the following update request.

curl -X POST \
  --header "Content-Type: application/json" \
  --header "Accept: application/json" \
  --header "Authorization: Bearer YOUR_API_KEY" \
  --data '{ \
    service_account: “GOOGLE_APPLICATION_CREDENTIALS”
 }' \
  https://api.telnyx.com/v2/dialogflow_connections/{connection_id}

Note that GOOGLE_APPLICATION_CREDENTIALS must be provided in a form of encoded json.

The google application credentials should be created for the google service account by following the Google Dialogflow ES Setup.

When the configuration is assigned to the application users can enable the Dialogflow integration for every outbound or inbound call.

Dialogflow CX

Note: To enable the integration between the Telnyx Voice API and Dialogflow CX, you'll need to register manually with Telnyx by reaching out to our support team in the Mission Control Portal.

Once registered, you'll need to assign your DialogFlow CX project to the Call Control connection using the following update request.

curl -X POST \
  --header "Content-Type: application/json" \
  --header "Accept: application/json" \
  --header "Authorization: Bearer YOUR_API_KEY" \
  --data '{ \
  "service_account": “GOOGLE_APPLICATION_CREDENTIALS”, \
  "conversation_profile_id": "GOOGLE_CONVERSATION_PROFILE_ID"
 }' \     
 https://api.telnyx.com/v2/dialogflow_connections/{connection_id}

Note that GOOGLE_APPLICATION_CREDENTIALS must be provided in a form of encoded json.

The process of creating GOOGLE_APPLICATION_CREDENTIALS is described on this page Google Dialogflow CX Setup

The conversation profile can be created from the Dialogflow CX console by selecting Agent Assist from the top menu.

Enabling Dialogflow CX for outbound calls

curl --location --request POST 'https://api.telnyx.com/v2/calls' \
--header 'Authorization: Bearer YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data-raw '{
  "to":"+48662211095",
  "from":"+13127367481",
  "connection_id":"1714376719458109299",
  "enable_dialogflow": true,
  "dialogflow_config": {
    "analyze_sentiment" : true,
    "partial_automated_agent_reply" : true
  }
}'

Enabling Dialogflow CX for inbound calls

curl -X POST \
  --header "Content-Type: application/json" \
  --header "Accept: application/json" \
  --header "Authorization: Bearer YOUR_API_KEY" \
  --data '{"enable_dialogflow": true}' \
  https://api.telnyx.com/v2/calls/{call_control_id}/actions/answer

When the integration is enabled, the audio provided by Dialogflow will be played on the call and the following webhooks will be delivered to the webhook url:

{
  "data": {
      "event_type": "dialogflow.detectintent.response",
      "id": "22cbf929-9a87-43ab-873b-b832ccf05a05",
      "occurred_at": "2022-05-23T16:01:53.301413Z",
      "payload": {
        "call_control_id": "v2:WE_lbN28P-h81n4xeceODATcx9J-FYci6WO4hP3Gp9Sb789WivnkMw",
        "call_leg_id": "a3dc0316-dab1-11ec-aaff-02420a0d6669",
        "call_session_id": "a3cf4428-dab1-11ec-84a9-02420a0d6669",
        "client_state": null,
        "confidence": 1,
        "connection_id": "1669581837548127492",
        "fulfillment_messages": [{
            "text": [
              "Hi! I'm the virtual car rental agent. I can help you start a new car rental reservation. How can I assist you today?"
            ]
          }
        ],
        "is_final": true,
        "stream_id": "eb724ae3-4f93-49d0-9ab5-c821b47c4fc5",
        "transcript": "hello"
    },
    "record_type": "event"
  },
  "meta": {
  "attempt": 1,
  "delivered_to": "https://webhook.site/e437011a-bb4a-4f34-8060-30e6604c2cf6"
  }
 }

In case of Dialogflow CX, when the live agent handoff option is enabled users will see the following "media_streaming_dialogflow_live_agent_handoff" webhook:

%{
  "created_at" => "2022-09-16T00:08:08.704289Z",
  "event_type" => "media_streaming_dialogflow_live_agent_handoff",
  "id" => "09c5a1b8-b4bf-4f8d-80f6-96b6e36c399e",
  "payload" => %{
    "call_control_id" => "v3:uzf9TGViqHGdXtLTESAXwFphwtO9vey7oRGw9fzVlaYlQ0obP9BeIQ",
    "metadata" => %{"dialogflow.ccai.live-agent-escalation" => %{}},
    "occurred_at" => nil,
    "stream_id" => "1cc67e75-4658-4c9d-a8d3-777dce200d6e"
  },
  "record_type" => "event"
}

Here, it is recommended to transfer a call to the agent using the transfer command.

Need some assistance?

If you need help setting up your Dialogflow integration, reach out to a member of our team through the Mission Control Portal.

Was this page helpful?