カスタム・イベントの送受信方法
Product deprecation notice
Effective April 30th, 2026, Vonage In-App Messaging will no longer be available. Access for new users will be closed, and the service will be discontinued for all existing users.
If you have any questions regarding this product’s discontinuation, please contact your account manager or our support team.
このガイドでは、Vonage Client SDKでカスタムイベントを送受信する方法を説明します。始める前に、アプリにSDKを追加し、セッション(アンドロイド, iOS, JSそして 会話に参加.
カスタム・イベントは、カスタム・データを持つイベントであり、カンバセーションに保存されます。 はかない出来事.従って、あなたが 会話のイベント が返されます。また、会話のイベントを取得する際に、カスタムイベントのタイプでフィルタリングすることもできます。
カスタムイベントはすべての人に配信される App カンバセーション内のメンバー。投票など、カンバセーションのカスタムアクションの実装に最適です。
カスタムイベントの送信
会話IDがあれば、カスタムイベントを送信することができます。イベントにはタイプを指定する必要があります。 タイプは以下のとおりです:
- そもそも
custom: - 合計100文字以内
- は英数字のみ、
:,-そして_文字 例えば、世論調査ではcustom:poll:questionそしてcustom:poll:response.
カスタム・データは4096バイトを超えてはならない。 カスタムデータにはJSONを使用することを推奨しますが、ここでは何でも送ることができます。
const customData = {
key1: "value 1",
key2: "value 2"
};
client.sendCustomEvent(conversationId, "custom:my-event", customData)
.then(timestamp => {
console.log("Successfully sent custom event at ", timestamp);
}).catch(error => {
console.error("Error sending custom event: ", error);
});
client.sendCustomEvent("CON_ID", "custom:myEvent","MY_CUSTOM_BODY") { error, timestamp ->
error?.takeIf { it is VGError }?.let {/* Handle Vonage Error */ } ?:
error?.let {/* Handle generic Error */ }
timestamp?.let { /* event sent at timestamp */ }
}
client.sendCustomEvent("CON_ID", eventType: "custom:myEvent", customData: "MY_CUSTOM_BODY") { error, timestamp in
...
}
カスタムイベントの受信
Event Listener/Delegate Functionをセットアップすることで、アプリケーションのすべてのConversation Eventを受け取ることができます。ここで、受信イベントの種類を確認することができます。受信するカスタムイベントのフィルタリングは eventType.
client.on("conversationEvent", event => {
switch (event.kind) {
case "custom":
handleCustomEvent(event); // event.eventType: custom event type
break;
};
});
client.setOnConversationEventListener {
when(it) {
is CustomConversationEvent -> {}
}
}
func chatClient(_ client: VGChatClient, didReceiveConversationEvent event: VGConversationEvent) {
switch event.kind {
case .custom:
// Handle Custom Event
let customEvent = event as! VGCustomConversationEvent
let customEventType = customEvent.eventType
...
}
}