LiveChatのwebhookについて調べたときの備忘録
LiveChat
https://www.livechatinc.com/jp/
この記事では、WebhookのTargetURLをGoogle Apps Script で作ったWebアプリのURLで試します。
- Webhookでデータを受け取るWebAppを作ります
- LiveChat側でWebhookの設定をします
1. Webhookでデータを受け取るWebAppを作ります
Google Apps Scriptのエディタに以下のコード.gsを書いて保存します。
コード.gsfunction doPost(e) { var contents = e.postData.contents console.log(contents); } | 意訳この機能がやること 受け取ったデータのcontentsを取得して ログに出す |
公開 > ウェブアプリケーションとして導入...を選択します
- バージョンの説明を入力して
- アプリケーションの実行ユーザは「自分」
- アクセスはできるのは「全員(匿名ユーザーを含む)」
で「導入」をクリックします。
(LiveChat側からこのアプリにアクセスできて実行できるように2, 3の設定は必須)
現在のウェブアプリケーションのURLのhttps://〜をコピーします
2. Webhook側の設定をします
Settings > Integrations > Webhooks を開きます
いつ=どのEventが起きた時に
どのデータ=Data type
どこに=Target URL(STEP1でコピーしたURL)
を設定して「Add a webhook」をクリックします
すると下部に以下のようなエリアが追加されます
これで設定したEventが起きた時にTarget URLにデータが飛んできます
Eventの chat starts と chat ends を試したときに取得したデータのメモ
chat startsのwebhook{ "event_type": "chat_started", "event_unique_id": "7ddaabb", "token": "31aae354", "license_id": "1067", "lc_version": "2", "chat": { "id": "PO13", "started_timestamp": 1552126412, "url": "URL", "referer": "", "messages": [{ "user_type": "agent", "author_name": "NAME", "agent_id": "name@gmail.com", "text": "Hello. How may I help you?", "json": "", "timestamp": 1552126412 }], "attachments": [], "events": [], "agents": [{ "name": "AGENT NAME", "login": "name@gmail.com" }], "tags": [], "groups": [0] }, "visitor": { "id": "S1551", "name": "NAME", "email": "name@gmail.com", "country": "Japan", "city": "", "language": "en", "page_current": "URL", "timezone": "" }, "pre_chat_survey": [{ "id": "2001", "type": "name", "label": "Name:", "answer": "NAME" }, { "id": "2002", "type": "email", "label": "E-mail:", "answer": "name@gmail.com" }] } | chat endsのwebhook{ "event_type": "chat_ended", "event_unique_id": "349a820", "token": "f791db42", "license_id": "1067", "lc_version": "2", "chat": { "id": "PO13", "started_timestamp": 1552126412, "ended_timestamp": 1552126503, "url": "URL", "referer": "", "messages": [{ "user_type": "agent", "author_name": "NAME", "agent_id": "name@gmail.com", "text": "Hello. How may I help you?", "json": "", "timestamp": 1552126412 }, { "user_type": "visitor", "author_name": "NAME", "text": "hello! how's it going?", "json": "", "timestamp": 1552126451 }, { "user_type": "agent", "author_name": "AGENT NAME", "agent_id": "name@gmail.com", "text": "Hi, good.", "json": "{}", "timestamp": 1552126490 }], "attachments": [], "events": [{ "user_type": "visitor", "text": "NAME closed the chat.", "timestamp": 1552126503, "type": "closed" }], "agents": [{ "name": "NAME", "login": "name@gmail.com" }], "tags": [], "groups": [0] }, "visitor": { "id": "S1551", "name": "NAME", "email": "name@gmail.com", "country": "Japan", "city": "", "language": "en", "page_current": "URL", "timezone": "" }, "pre_chat_survey": [{ "id": "2001", "type": "name", "label": "Name:", "answer": "NAME" }, { "id": "2002", "type": "email", "label": "E-mail:", "answer":"name@gmail.com" }] } |
参考
LiveChat
https://www.livechatinc.com/jp/
dashboard
https://dashboard.labs.livechatinc.com/
Building webhook integration
https://developers.livechatinc.com/docs/build-integration/
LiveChat
https://www.livechatinc.com/jp/
dashboard
https://dashboard.labs.livechatinc.com/
Building webhook integration
https://developers.livechatinc.com/docs/build-integration/