カスタムイベントの追加
カスタムイベントは会話にメタデータを追加するために使用できます。カスタムイベントの使用にはいくつかの制限があります:
- イベントタイプは
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.
Run your code
Save this file to your machine and run it:
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.
Create a file named create-custom-event.js and add the following code:
const { Vonage } = require('@vonage/server-sdk');
const vonage = new Vonage({
applicationId: VONAGE_APPLICATION_ID,
privateKey: VONAGE_PRIVATE_KEY,
});Write the code
Add the following to create-custom-event.js:
vonage.conversations.createEvent(
CONV_ID,
{
'type': 'custom:YOUR_EVENT_NAME',
'from': CONV_EVENT_FROM,
'body': {
'your': 'data',
},
},
)
.then((event) => console.log(event))
.catch((error) => console.error(error));Run your code
Save this file to your machine and run it:
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.
Add the following to build.gradle:
implementation 'com.vonage:server-sdk:9.3.1'Create a class named CreateCustomEvent and add the following code to the main method:
Run your code
We can use the アプリケーション plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
apply plugin: 'application'
mainClassName = project.hasProperty('main') ? project.getProperty('main') : ''Run the following gradle command to execute your application, replacing com.vonage.quickstart.conversation with the package containing CreateCustomEvent:
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.
Create a file named CreateCustomEvent.cs and add the following code:
Add the following to CreateCustomEvent.cs:
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.
Create a file named create-custom-event.php and add the following code:
Run your code
Save this file to your machine and run it:
試してみる
コードを実行すると、カスタム・イベントがあなたの イベントリスト