Difference between revisions of "PEC-Developer/Current/SCAPI/MessengerNamespace"

From Genesys Documentation
Jump to: navigation, search
(Published)
 
 
Line 37: Line 37:
 
{{!}}-
 
{{!}}-
 
{{!}}succeeded
 
{{!}}succeeded
{{!}}string
+
{{!}}function
{{!}}The callback function to use if the operation succeeded.
+
{{!}}A function called when the operation succeeds.
 
{{!}}-
 
{{!}}-
 
{{!}}failed
 
{{!}}failed
{{!}}string
+
{{!}}function
{{!}}The callback function to use if the operation failed.
+
{{!}}A function called when the operation fails.
 
{{!}}}
 
{{!}}}
 
{{!}}}
 
{{!}}}

Latest revision as of 13:44, February 22, 2023

This topic is part of the manual Service Client API Reference for version Current of Developer.

Learn about the Messenger namespace methods in the Service Client API.

Methods

The Messenger namespace includes the following methods:

broadcastMessage

Signature <static> broadcastMessage(channel, message, succeeded, failed)
Description Send a message to other web applications that use the Service Client API and have subscribed to the specified channel.
Parameters
Name Type Description
channel string The channel to send the message on.
message object The message (any JSON object) to broadcast on the channel.
succeeded function A function called when the operation succeeds.
failed function A function called when the operation fails.

Samples

// Add a new message broadcaster:
genesys.wwe.service.messenger.broadcastMessage("my-channel", { foo: "A foo text.", bar: 1234 }, succeeded, failed)
// The operation "broadcastMessage" from the service "messenger" takes a channel name and any JSON-compliant object.
 
// In order to receive this message, you must "subscribe" to "my-channel":
genesys.wwe.service.subscribe([ "messenger:my-channel" ], function(message) { console.log("message: " + message.data); }, this);
// It is possible to subscribe to several channels:
genesys.wwe.service.subscribe([ "messenger:my-channel", "messenger:my-channel2" ], function(message) {
  console.log("message: " + message.data + ", channel: " + message.event);
}, this);
When a message is broadcast to your channel, you receive an event called messenger:<channel> with the message in the data attribute. For example, here's the event for the broadcast in the sample above:
{
  "event": "messenger:my-channel",
  "data": {
    "foo": "A foo text.",
    "bar": 1234
  },
  "userAgent": "WWE Server",
  "protocolVersion": 2
}
Comments or questions about this documentation? Contact us for support!