Apps Scriptリファレンス: Apps Script Reference |障害・課題追跡: IssueTracker |Google Workspace: Status Dashboard - Summary

2019年4月16日火曜日

LiveChatのwebhookを使ってみる(チャット中と終了後にタグを更新したログ)


チャット中に tag を追加して [chat_changed]
チャットが終わって [chat_ended]
そのあと tag を追加する [chat_changed]

というログを取得した

テスト用に作ったLiveChatアカウントですが、一応 id などは短くしています


関連記事

LiveChatのwebhookを使ってみる
LiveChatのwebhookを使ってみる(チャット終了時にタグを更新する)



コード.gs
function doPost(e) {
  var contents = e.postData.contents
  console.log(contents);
}
意訳
この機能がやること
受け取ったデータのcontentsを取得して
ログに出す




support tag 追加
{
  "event_type": "chat_changed",
  "token": "c8efe",
  "license_id": "1079",
  "chat": {
    "agents": [{
      "name": "NAME",
      "login": "name@googlegroups.com"
    }],
    "ended_timestamp": 1555365127,
    "groups": [0],
    "id": "PQ80B",
    "messages": [{
      "agent_id": "name@googlegroups.com",
      "author_name": "NAME",
      "text": "Hello. How may I help you?",
      "timestamp": 1555365102,
      "user_type": "agent"
    }, {
      "author_name": "NAME",
      "text": "hello! how's it going?",
      "timestamp": 1555365127,
      "user_type": "visitor"
    }],
    "started_timestamp": 1555365102,
    "tags": ["support"],
    "url": "URL"
  },
  "visitor": {
    "email": "name@gmail.com",
    "id": "S1555",
    "name": "NAME",
    "custom_variables": []
  }
}




































chat 終了
{
  "event_type": "chat_ended",
  "event_unique_id": "6ddc4",
  "token": "d8f7c",
  "license_id": "1079",
  "lc_version": "2",
  "chat": {
    "id": "PQ80B",
    "started_timestamp": 1555365102,
    "ended_timestamp": 1555365168,
    "url": "URL",
    "referer": "",
    "messages": [{
      "user_type": "agent",
      "author_name": "NAME",
      "agent_id": "name@googlegroups.com",
      "text": "Hello. How may I help you?",
      "json": "",
      "timestamp": 1555365102
    }, {
      "user_type": "visitor",
      "author_name": "NAME",
      "text": "hello! how's it going?",
      "json": "",
      "timestamp": 1555365127
    }, {
      "user_type": "agent",
      "author_name": "NAME",
      "agent_id": "name@googlegroups.com",
      "text": "Hi, good.",
      "json": "{}",
      "timestamp": 1555365162
    }],
    "attachments": [],
    "events": [{
      "user_type": "visitor",
      "text": "NAME closed the chat.",
      "timestamp": 1555365168,
      "type": "closed"
    }],
    "agents": [{
      "name": "NAME",
      "login": "name@googlegroups.com"
    }],
    "tags": ["support"],
    "groups": [0]
  },
  "visitor": {
    "id": "S1555",
    "name": "NAME",
    "email": "name@gmail.com",
    "country": "Japan",
    "city": "city",
    "language": "en",
    "page_current": "URL",
    "timezone": "Asia/Tokyo"
  },
  "pre_chat_survey": [{
    "id": "2001",
    "type": "name",
    "label": "Name:",
    "answer": "NAME"
  }, {
    "id": "2002",
    "type": "email",
    "label": "E-mail:",
    "answer": "name@gmail.com"
  }]
}


positive feedback tag 追加
{
  "event_type": "chat_changed",
  "token": "c8efe",
  "license_id": "1079",
  "chat": {
    "agents": [{
      "name": "NAME",
      "login": "NAME@googlegroups.com"
    }],
    "ended_timestamp": 1555365168,
    "events": [{
      "text": "NAME closed the chat.",
      "timestamp": 1555365168,
      "user_type": "visitor"
    }, {
      "text": "NAME rated this chat as good.",
      "timestamp": 1555365173,
      "user_type": "visitor"
    }],
    "groups": [0],
    "id": "PQ80B",
    "messages": [{
      "agent_id": "name@googlegroups.com",
      "author_name": "NAME",
      "text": "Hello. How may I help you?",
      "timestamp": 1555365102,
      "user_type": "agent"
    }, {
      "author_name": "NAME",
      "text": "hello! how's it going?",
      "timestamp": 1555365127,
      "user_type": "visitor"
    }, {
      "agent_id": "name@googlegroups.com",
      "author_name": "NAME",
      "text": "Hi, good.",
      "timestamp": 1555365162,
      "user_type": "agent"
    }],
    "started_timestamp": 1555365102,
    "tags": ["support", "positive feedback"],
    "url": "URL"
  },
  "visitor": {
    "email": "name@gmail.com",
    "id": "S1555",
    "name": "NAME",
    "custom_variables": []
  }
}























Latest post

Googleドキュメントに見出しを追加したい

今回の例では、ドキュメントの末尾に「見出しD」 を追加します。 見出しA, B, C, Dのスタイルは、見出し3 ( HEADING3 ) に設定しています。  下記Code.gsの  GOOGLE_DOCUMENT_URL を設定して  addHeadingToEnd()  を...