Skip to content
Jonas Gossens edited this page Aug 6, 2021 · 1 revision

Sending messages

Message object

The message object has to contain at least the text property. The images array is optional. Only urls from chayns image services are allowed.

  • text : string - The message you want to send.
  • images: array of strings - (optional) urls of images you want to sent.

chayns.intercom.sendMessageToUser(userId, config)

Sends an intercom message to the user that belongs to the ID.

Parameter

  • userId : number - The id of the user you want to contact.
  • config : message object

chayns.intercom.sendMessageToPage(config)

Sends an intercom message to the staff of the page.

Parameter

  • config : message object

chayns.intercom.sendMessageToGroup(groupId, config)

Sends an intercom message to the uac-group that belongs to the ID. The message will be sent in the name of the chayns site. Only available if the user is a manager on the chayns site.

Parameter

  • groupId : string - The id of a group of the current site.
  • config : message object

Example

Here's an example for sending a message to another user:

chayns.intercom.sendMessageToUser(userId, {
  text: 'Hi this is a message.'
}).then((data) => {            
   if(data.status === 200)
       chayns.dialog.alert('','thank you');
});

BB-Codes

When sending a message you can add different BB-Codes to the text to display HTML elements inside the message.

Format text

There are some BB-Codes to format the text for the message. All codes are replaced by their corresponding HTML codes. You can see the supported codes and their effect in the table below:

BB-Code HTML code Effect
[b]Intercom[/b] <b>Intercom</b> bold
[i]Intercom[/i] <i>Intercom</i> italic
[u]Intercom[/u] <u>Intercom</u> underline
[s]Intercom[/s] <s>Intercom</s> strikethrough
[center]Intercom[/center] <center>Intercom</center> center

HTML elements

There are also some BB-Codes to handle HTML elements in the message text. You must use the BB-Codes instead of HTML tags because the HTML tags will be ignored to prevent script injection.
The following codes are supported:

BB-Code HTML code Element
[h1]...[/h1] <h1>...</h1> Headline 1
[h2]...[/h2] <h2>...</h2> Headline 2
[h3]...[/h3] <h3>...</h3> Headline 3
[ul]...[/ul] <ul>...</ul> Unordered List Wrapper
[ol]...[/ol] <ol>...</ol> Ordered List Wrapper
[li]...[/li] <li>...</li> List Item
[p]...[/p] <p>...</p> Paragraph
[span]...[/span] <span>...</span> Span
Styles

You can add styles for h1, h2, h3, p and span tags in the following syntax:

[span style="font-size: 20px;"]Intercom[/span]

List-Element

To display a list in the message, either an "ul" or "ol" element must be used as the wrapper. Within the wrapper, the entries can then be inserted in "li" elements.

Example for unordered list:
[ul][li]First entry[/li][li]Second entry[/li][/ul]

Result for unordered list:

  • First entry
  • Second entry

Example for ordered list:
[ol][li]First entry[/li][li]Second entry[/li][li]Third entry[/li][/ol]

Result for ordered list:

  1. First entry
  2. Second entry
  3. Third entry

Important: In order to display the lists correctly, there must be no spaces between the "ul/ol" and "li" elements.

Button

There is a special BB-Code to add buttons to the intercom message. The using of this button is a bit different to buttons in normal HTML. Buttons must have the following syntax:

[button <parameter>="<value>"]<buttonName>[/button]

Several parameters can be added to a button:

  • inline: If value is true the button will be displayed inline (optional)
  • url: The url to open (optional, but used as fallback for tappId)
  • urlParameters: The urls parameters will be added to selectTapp call and openUrl (in url notation without leading "?" or "&") (optional)
  • tappId: TappId of tapp to open (optional)
  • siteId: SiteId of site to open in chayns app (optional)
  • locationId: LocationId of site to open tapp on (optional)
  • buttonName: Text which will be displayed on the button

Here is an example:

[button tappId="250359" url="de.tobit.software/id/money" inline="true" urlParameters="test1=true&test2=42"]Your Money[/button]

The button above will select the money tapp in chaynsId and adds the url parameters test1=true and test2=42. Also the button will be displayed inline.

Information: If the locationId parameter is given the tapp will only change if the user is on the correct site. Otherwise the url will be opened.

Information: If the siteId is given, the user is in the chayns app and the tapp for locationId and tappId could not be found, the site will be opened there directly in the app instead of in the browser.

Warning: When the tappId or locationId not match and there is no url given, nothing will happen on button click.

Link

Links can also be added to messages. A link works as same as a button but is displayed as a normal HTML a-Tag.

Links work exactly like buttons but have the following syntax:

[link <parameter>="<value>"]<linkName>[/link]

All parameters given for buttons can be used for links too. The inline parameter is not necessary for links because they will be displayed inline every time.

Open intercom chats

There can be used different url parameters in the intercom to affect it. The following parameters can be used:

Parameter Effect
isLocation show intercom in site mode
chaynsId direct open chat with user by chaynsId (XXX-XXXXX)
lid direct open chat with site by locationId
tid direct open chat by thread id
forceNew opens new thread view and selects member for given chaynsID or LID even when chat already exists
hideBack hides the headline bar of intercom and sets thread name as website title

Information: The parameter "LID" will be later replaced with "siteID" to open chat with site by siteID of locations.

Information: The parameters can be used in url directly or in chayns.selectTapp().

Examples to open chats:

// This opens the chat with XXX-XXXXX or creates new thread view if thread not given
chayns.selectTapp({
    id: 251441,
    params: 'chaynsId=XXX-XXXXX',
});

// This opens new thread view and preselects Tobit.Software as receiver even if chat with Tobit.Software already exists
chayns.selectTapp({
    id: 251441,
    params: 'lid=1214&forceNew',
});

// This opens the chat for the given thread id
chayns.selectTapp({
    id: 251441,
    params: 'tid=<threadId>', // Insert threadId here
});