Himanshu Sharma
Himanshu Sharma

Reputation: 1

How to integrate LiveChat Dashboard with Google Dialogflow for agents handoff?

When user ask or select option for "agent"/"chat with an agent" on google dialogflow chatbot then it should transfer the chat to LiveChat(https://www.livechat.com/) dashboard so that agent take over from chatbot.

Upvotes: 0

Views: 683

Answers (1)

Jay
Jay

Reputation: 11

To pass data into LiveChat from a page without LiveChat chat window installed on it, you can use the following method from LiveChat API: https://developers.livechat.com/docs/messaging/agent-chat-api#create-customer to create a customer

afterwards, start a chat as that customer:

https://developers.livechat.com/docs/messaging/customer-chat-api#start-chat

once chat is started - you can submit events using this method: https://developers.livechat.com/docs/messaging/customer-chat-api#send-event

for all of the above you'll need to provide authorization, please see below: https://developers.livechat.com/docs/authorization/authorizing-api-calls

for authorization you'll need an account in LiveChat Developer Console: https://developers.livechat.com/console/

In the Console you can also find contact to LiveChat Developer Community (Discord and email)

EDIT: here's how it looks like more hands on:

  1. First thing we need to do is acquire authentication - in this case we want to act as a customer, there are a few ways to authenticate as customer - below are instructions regarding all the methods: https://developers.livechat.com/docs/authorization/authorizing-api-calls#case-new-customer

I'll use Agent token grant method and acquire Customer access token by sending following curl:

curl --location --request POST 'https://accounts.livechat.com/customer/token' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer dal:xxxFpzmIHk5c86Zwn3uf2YunhGk' \
--data-raw '{
"grant_type": "agent_token",
"client_id": "3xxx45a50544060cedc26c90644f7677",
"response_type": "token",
"redirect_uri": "https://my.livechatinc.com"
}
'

And here's the response received:

{
    "access_token": "dal:xxx-zH-fTOKYJsUolAKzow",
    "client_id": "xxx145a50544060cedc26c90644f7677",
    "entity_id": "xxx1d260-e284-44c0-53d2-3e958f74488a",
    "expires_in": 28800,
    "token_type": "Bearer"
}
  1. Once customer access token is acquired we'll be looking to send the "start chat" method

This request requires a parameter called "organization_id" - that's an unique identifier of your account across all LiveChat Inc. products that's static so we'll need to only get it once, you can get it by sending following curl:

curl --location --request GET 'https://api.livechatinc.com/v3.4/configuration/action/get_organization_id?license_id=1234567'

License ID required for the above can be found inside of your LiveChat tracking code here: https://my.livechatinc.com/settings/code

Sending the request will provide you with "organization_id" in the response:

{
    "organization_id": "xxx29b0e-012c-4384-9f72-614324ec0xxx"
}

Now that we have everything - we can start the chat:

curl --location --request POST 'https://api.livechatinc.com/v3.4/customer/action/start_chat?organization_id=xxx29b0e-012c-4384-9f72-614324ec0741' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer dal:xxx-zH-fTOKYJsUolAKzow' \
--data-raw '{}'

And the response looks like this:

{
    "chat_id": "R5MUSNS1I5",
    "thread_id": "R5MUSNS1J5"
}

chat_id property from the above response will be useful for sending events and resuming the chat should the visitor want to chat again in the future

  1. To send a message we'll be using the "send_event" method, curl below:
curl --location --request POST 'https://api.livechatinc.com/v3.4/customer/action/send_event?organization_id=xxx29b0e-012c-4384-9f72-614324ec0741' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer dal:xxx-zH-fTOKYJsUolAKzow' \
--data-raw '{
    "chat_id": "R5MUSNS1I5",
    "event": {
      "type": "message",
      "text": "hello world",
      "recipients": "all"
    }
  }'

And here's the result: incoming chat

I hope that helps!

Upvotes: 1

Related Questions