Skip to content

PostMessage

Posts a new message to a channel.

1
$Domain.PostMessage(channelId: string, msg: ChannelMessage):ChannelMessageResult

Parameters

string channelId
    The ID of the channel to post the message to.

ChannelMessage msg
    The message properties.

Returns

A ChannelMessageResult instance containing the results of the operation.

Remarks

This method performs different actions depending on whether the given input has an Id property:

  • If no Id is specified, it simply posts a new activity message on the channel with the given subject and content. This is useful for notification purposes.
  • When an Id is given, the method first checks if a message with the specified Id was previously sent on the channel. If a previously sent message is found, it does not create a new activity and returns the existing Case instance.
  • If the input contains a references property, it also checks for previously sent messages with the referenced IDs. If any reference is found, it creates a new activity that is linked to the matching case and returns the existing Case instance.
  • When nothing matches, it creates a new Case on the channel with the activity and returns it.
  • If case management is not enabled on the channel, it always posts a new activity on the channel without a Case instance.

The channel must resolve in the current domain and msg must be a JavaScript object. Posting is a state-changing channel operation. The returned IsNew is false when the channel recognizes an already processed message; Case and Id are present only when the processing result includes them.

Examples

Post a notification to a channel

1
2
3
4
5
6
var channelId = $Xml.Evaluate('ChannelId');

$Domain.PostMessage(channelId, {
    Subject : 'Order ' + $Xml.Evaluate('Id') + ' shipped',
    Description : 'The order was shipped on ' + $Calendar.Today.toISOString()
});

Create a case and add a follow-up message

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
var channelId = $Xml.Evaluate('ChannelId');
var ticketId = 'ticket-' + $Xml.Evaluate('TicketNumber');

// the first message creates the case
var result = $Domain.PostMessage(channelId, {
    Id : ticketId,
    Subject : $Xml.Evaluate('Subject'),
    Description : $Xml.Evaluate('Description')
});

// a message that references it is added to the same case
$Domain.PostMessage(channelId, {
    Id : ticketId + '-update-1',
    References : [ticketId],
    Subject : 'Status update',
    Description : 'The ticket is being investigated.'
});

See Also