Lightning Experience の sendCustomEvent()
特定のチャットキーを持つチャットのクライアント側のチャットウィンドウにカスタムイベントを送信します。このメソッドは、Lightning コンソールアプリケーションでのみ機能します。
引数
| 名前 | 型 | 説明 |
|---|---|---|
| argumentObj | Object | このメソッドに渡されるすべての引数が含まれるオブジェクト。 |
argumentObj
| 名前 | 型 | 説明 |
|---|---|---|
| recordId | String | カスタマイズするイベントの ID。 |
| type | String | カスタムイベント種別の名前。 |
| data | String | カスタムイベントに関連付けられているデータ。 |
サンプルコード
この例では、カスタムイベントを公開して結果を記録します。
コンポーネントコード:
1<aura:component implements="flexipage:availableForAllPageTypes" access="global" description="Conversation toolkit api sample">
2 <aura:attribute name="recordId" type="String" />
3 <lightning:conversationToolkitAPI aura:id="conversationKit" />
4 <ui:button label="sendCustomEvent" press="{!c.sendCustomEvent}" />
5</aura:component>コントローラーコード:
1({
2 sendCustomEvent: function(cmp, evt, helper) {
3 var conversationKit = cmp.find("conversationKit");
4 var recordId = cmp.get("v.recordId");
5 var type = "myCustomEventType";
6 var data = "myCustomEventData";
7 conversationKit.sendCustomEvent({
8 recordId: recordId,
9 type: type,
10 data: data
11 })
12 .then(function(result){
13 if (result) {
14 console.log("Successfully sent custom event");
15 } else {
16 console.log("Failed to send custom event");
17 }
18 });
19 }
20})カスタムイベント種別は、カスタムイベントの名前と一致する必要があります。myCustomEventType を独自のカスタムイベント名に置き換えます。
応答
Promise を返します。Promise が満たされた場合、Success が示されます。catch 句が呼び出された場合、Failure が示されます。