UNPKG

node-red-contrib-salesforce

Version:

A set of Node-RED nodes to interact with Salesforce and Force.com.

114 lines (110 loc) 5.57 kB
<script type="text/javascript"> RED.nodes.registerType('streaming', { category: 'Salesforce', color: '#C0DEED', defaults: { name: { value: '' }, pushTopic: { value: '', required: true }, replayId: { value: '-1', required: true }, resubScribeOnDoubeSubscription: { value: false }, connection: { value: '', type: 'connection-config', required: true } }, inputs: 1, outputs: 1, icon: 'salesforce.png', label: function() { return this.name || 'streaming'; }, oneditsave: function() { this.topicType = $('#node-config-input-topicType').val(); } }); </script> <script type="text/x-red" data-template-name="streaming"> <div class="form-row"> <label for="node-input-name"><i class="icon-tag"></i> Name</label> <input type="text" id="node-input-name" placeholder="Name"> </div> <div class="form-row"> <label for="node-input-connection"><i class="fa fa-plug"></i> Connection</label> <input type="text" id="node-input-connection"> </div> <div class="form-row"> <label for="node-input-pushTopic"><i class="fa fa-bullhorn"></i>Topic</label> <input type="text" id="node-input-pushTopic"> </div> <div class="form-row"> <label for="node-input-replayId"><i class="fa fa-repeat"></i>replayId</label> <input type="text" id="node-input-replayId"><br /> -2 for all available, -1 for new ones, number for a specific one </div> <div class="form-row"> <input type="checkbox" id="node-config-input-resubScribeOnDoubeSubscription" style="display: inline-block; width: auto; vertical-align: top;"> <label for="node-config-input-resubScribeOnDoubeSubscription" style="width: auto; white-space:nowrap;">Disconnect and reconnect on second subscription</label> (otherwise: ignore and stay subscribed) </div> </script> <script type="text/x-red" data-help-name="streaming"> <p>Creates a client that subscribes to a PushTopic for all things streaming API including CDC</p> <p>You need to provide the full topic starting with <code>/</code>. Samples:</p> <ul> <li>Platform events:<code>/event/DataChange__e</code><br /> Listen to the Platform event API</li> <li>Push Topic: <code>/topic/MyPushTopic</code> <br /> Listen to changes in sObjects</li> <li>Streaming (Generic): <code>/u/notifications/TestChannel</code><br /> Listen to generic Push Topics (deprecated)</li> <li>Change Data Capture: <ul> <li>All configured changes: <code>/data/ChangeEvents</code></li> <li>Opportunity: <code>/data/OpportunityChangeEvent</code></li> <li>Custom object: <code>Custom__ChangeEvent</code> (replacing <code>__c</code> with <code>__ChangeEvent</code>)</li> </ul> Check the <a href="https://developer.salesforce.com/docs/atlas.en-us.218.0.change_data_capture.meta/change_data_capture/cdc_subscribe_channels.htm">Developer guide for more details</a> </li> </ul> <p><b>replayId</b> (<a href="https://developer.salesforce.com/docs/atlas.en-us.api_streaming.meta/api_streaming/using_streaming_api_durability.htm">Read this</a>):</p> <ul> <li><code> -2 </code>: all available events (up to 24h or more back)</li> <li><code> -1 </code>: new events only </li> <li><code> number </code>: replay starting from that number</li> </ul> <p>Subscription starts only when an incoming message is received once. The following `msg` properties are supported:</p> <ul> <li><code>action</code> with the value <code>subscribe</code> or <code>unsubscribe</code> (default: <code>subscribe</code>): start or stop a subscription</li> <li><code>topic</code> the topic to subscribe to. Default is to use the topic from the config</li> <li><code>replayId</code> replays available events from this Id. Set to <code>-2</code> to get all current objects</li> <li><code>sf</code> object containing: <code>username</code>, <code>password</code>, <code>consumerKey</code> and <code>consumerSecret</code>. When the configuration allows it (checkbox "allow message credentials"), these values take priority over the configuration values). They don't have to be present together, they are applied individually</li> </ul> <p>When the client receives a message it sends <code>msg.payload</code> with the following: <ul> <li>msg.payload.event - the information on the event that was received.</li> <li>msg.payload.sobject - the sobject information received.</li> </ul> </p> <p>Assuming the PushTopic was created with the query <code>SELECT Id, Name FROM Contact</code>, then a resulting message would look like:</p> <pre>{ "event": { "type": "updated", "createdDate": "2015-07-31T18:38:21.000+0000" }, "sobject": { "Name": "Nikola Tesla", "Id": "a0037000001pplrZZZ" } }</pre> <p>See the <a href="https://developer.salesforce.com/docs/atlas.en-us.api_streaming.meta/api_streaming/quick_start_workbench.htm">Quick Start Using Workbench</a> to get started or the <a href="https://developer.salesforce.com/docs/atlas.en-us.api_streaming.meta/api_streaming/" target="_blank">Streaming API documentation</a> for complete details.</p> </script>