カスタムイベントの追加

カスタムイベントは会話にメタデータを追加するために使用できます。カスタムイベントの使用にはいくつかの制限があります:

  • イベントタイプは custom:
  • イベントタイプは100文字以内
  • イベントタイプは英数字のみ、 - そして _ 文字
  • イベント本体は4096バイトを超えてはならない

以下の変数が、便利な方法で必要な値に設定されていることを確認してください:

キー説明
CONVERSATION_ID

The ID of the Conversation.

MEMBER_ID

The unique ID of the Member.

Prerequisites

You will need to use an existing Application that contains a Conversation in order to be able to add a custom event. See the Create Conversation code snippet for information on how to create an Application and some sample Conversations.

Write the code

Add the following to create-custom-event.sh:

# `from` is only required if you're using a JWT with a `sub` claim
curl -X "POST" "https://api.nexmo.com/v1/conversations/$CONV_ID/events" \
     -H 'Authorization: Bearer '$JWT\
     -H 'Content-Type: application/json' \
     -d $'{
  "type": "custom:YOUR_EVENT_NAME",
  "from": "'$CONV_EVENT_FROM'",
  "body": {
    "your": "data"
  }
}'

View full source

Run your code

Save this file to your machine and run it:

sh create-custom-event.sh

試してみる

コードを実行すると、カスタム・イベントがあなたの イベントリスト