---
schema_version: "1"
id: 5cdc4892778b4a3bafc00e5eea39ba67521cf2c2c0c61e0b498bfc455fd2f370
title: Create a Custom Component to Trigger an Action
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/service/264-0-0/voice_conversation_intelligence_custom_component.md
canonical_url: https://help.salesforce.com/s/articleView?id=service.voice_conversation_intelligence_custom_component.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 7c928cf22ea257e135404a44d5c6d7779c17439aede6adf0b9dc1f8fb8241a6d
description: To subscribe to intelligence signals defined in your telephony system and trigger actions based on those signals, create Aura custom components in Salesforce. For example, create an action that recommends that the support rep offer a discount if the customer asks to cancel the service due to a poor customer experience. To create a custom component, pass the detected signal to a Recommendation Strategy flow and link the flow to the Einstein Next Best Action component in a Lightning page.
products:
  - Service Cloud
release: "264"
---
# Create a Custom Component to Trigger an Action

To subscribe to intelligence signals defined in your telephony system and trigger actions based on those signals, create Aura custom components in Salesforce. For example, create an action that recommends that the support rep offer a discount if the customer asks to cancel the service due to a poor customer experience. To create a custom component, pass the detected signal to a Recommendation Strategy flow and link the flow to the Einstein Next Best Action component in a Lightning page.

### Required Editions

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small edition"><colgroup><col></colgroup><tbody><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;"><a href="https://help.salesforce.com/s/articleView?id=service.service_editions_reference.htm&amp;language=en_US" target="_blank">View supported editions</a>.</td></tr></tbody></table>

Let’s look at an example where you create a custom component called Voice Intelligence Tester (ConversationIntelligenceTester.cmp).

1. Create the custom component. This custom component subscribes to the Salesforce Voice Aura Toolkit API.
    
    ```
    <aura:component implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" >
      <!-- Subscribe to the Salesforce Voice Toolkit API -->
      <force:serviceCloudVoiceToolkitApi aura:id="voiceToolkitApi"/>
      <force:recordData recordId="{!v.recordId}" layoutType="FULL" targetFields="{!v.record}" fields="VendorCallKey"/>
      <aura:handler name="init" value="{!this}" action="{!c.onInit}"/>
      <aura:handler name="destroy" value="{!this}" action="{!c.onDestroy}"/>
    
      <!-- Get record data -->
      <aura:attribute name="record" type="Object"/>
    
    </aura:component>
    ```
    
    ![Important](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-service-support-264-0-0-production-enus/dd14551c-a772-4db6-9a1d-d84df8df2980/images/icon_important.png)
    
    Important When you create a custom component, Conversation Intelligence supports using only Salesforce Voice Aura Toolkit API, not Salesforce Voice Lightning Web Component Toolkit API.
2. Create the controller resource (ConversationIntelligenceTesterController.js). This resource subscribes and listens to signals defined in your telephony system rules.
    
    ```
    
    ({
      onInit: function(cmp, event, helper) {
        helper.subscribeToVoiceToolkit(cmp);
      },
    
      onDestroy: function(cmp, event, helper) {
        helper.unsubscribeFromVoiceToolkit(cmp);
      }
    })
    ```
3. Create the helper resource (ConversationIntelligenceTesterHelper.js). This resource listens for the new Toolkit API conversation event, INTELLIGENCE\_SIGNAL, processes each detected signal, and triggers the next best action (NBA) based on the category name defined in your telephony system rule. In this example, it triggers the next best action if the category name is CustomerAttritionRiskWithNegSentiment.
    
    ![Important](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-service-support-264-0-0-production-enus/dd14551c-a772-4db6-9a1d-d84df8df2980/images/icon_important.png)
    
    Important Ensure that the payload attribute name of the updateNextBestActions method matches the input variable label in the Recommendation Strategy flow. In this example, the attribute is category.
    
    ```
    ({
      subscribeToVoiceToolkit: function(cmp) {
        // Subscribe to the INTELLIGENCE_SIGNAL event type
        cmp._signalEventListener =   $A.getCallback(this.signalEventListener.bind(this, cmp));
     cmp.find('voiceToolkitApi').addConversationEventListener('INTELLIGENCE_SIGNAL', cmp._signalEventListener);
      },
    
      unsubscribeFromVoiceToolkit: function(cmp) {
        cmp.find('voiceToolkitApi').removeConversationEventListener('INTELLIGENCE_SIGNAL', cmp._signalEventListener);
      },
    
      signalEventListener: function(cmp, signal) {
        this.processIntent(cmp, signal);
      },
    
      processIntent: function(cmp, signal) {
        var data = cmp.get('v.data');
        var events = signal.detail.events;
        for (var i = 0; i < events.length; i++) {
          var category = {};
          category.category = events[i].value;
          category.service = events[i].service
          // Filter the signal and decide the action
          // CustomerAttritionRiskWithNegSentiment is a category value 
          // defined in the Amazon Connect rule
          if (events[i].value === 'CustomerAttritionRiskWithNegSentiment') {
            this.triggerNBA(cmp, events[i].value);
          }
        }
      },
    
      triggerNBA: function(cmp, value) {
        var params ={
          category: [value]
        };
        cmp.find('voiceToolkitApi').updateNextBestActions(cmp.get('v.recordId'), params);
      }
    })
    ```

#### See Also

- [_Lightning Aura Components Developer Guide_: Configure Components for Lightning Pages and the Lightning App Builder](https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/components_config_for_app_builder.htm)
- [Salesforce Voice Aura Toolkit API Conversation Events](https://developer.salesforce.com/docs/atlas.en-us.voice_developer_guide.meta/voice_developer_guide/voice_lc_toolkit_using_conversation.htm)