Skip to main content

sms-sdk-renderer-python

SDK renders symphony messages using precompiled Handlebars templates both in bots and in applications.

User Guide

Now, there are several message templates that you can choose:

Name Description
SIMPLE Renders a message in simple format
ALERT Renders a message formatted as an alert
INFORMATION Renders a general information messages
NOTIFICATION Renders a message formatted as a notification
TABLE Renders a collection of objects in the table format
LIST_TEMPLATE Renders a list of values
BUTTON Renders a button element
TEXTFIELD Renders a textfield element
CHECKBOX Renders a checkbox element
TEXTAREA Renders a textarea element
RADIOBUTTON Renders a radio button element
PERSONSELECTOR Renders a person selector element
DROPDOWN_MENU Renders a dropdown menu element
TABLE_SELECT Renders a table element
FORM Renders a form element

Prerequisites

Please make sure the following tools are installed:

  • pybars3==0.9.6

Install SDK

$ pip install sms-sdk-renderer-python

How to use

  • Import the sdk:
import sms_sdk_renderer_python.lib.sms_sdk_renderer as SmsRenderer
  • Create a message object like that, for the ALERT template:
alert_data = {
    "title": 'Informaiton Title',
    "content": 'This is a information message',
    "description": 'Information message description'
}

In the bot

  • In the code, compile your message using the command:
alert_message = SmsRenderer.renderInBot(alert_data, SmsRenderer.smsTypes['ALERT'])
  • Send the message with Symphony API SDK:
self.bot_client.get_message_client().send_msg(msg['stream']['streamId'], alert_message)
  • If you wish to create a form that contains many elements, use the renderForm(message, smsType):

A sample complex_form_data json object:

form_data = {
    "header" : {"title":"Test Form",
                "titleSize": 4,
                "formId": "test_form_id"},
    "body": [{"textfield":{
                "name":"exmaple-text-field",
                "placeholder": "example-placeholder",
                "required": "true",
                "masked": "true",
                "minlength": 1,
                "maxlength": 128
    }},
            {"textarea":{
                "name":"exmaple-text-area",
                "placeholder": "example-placeholder",
                "required": "true"
            }},
            {"checkbox":{
                "name":"example-name",
                "value":"example-value",
                "checked": "false",
                "text":"Red"
            }},
            {"dropdown_menu" : {
            "name":"dropdown-name",
            "required": "true",
            "options": [{"value":"value1", "selected":"true", "text":"First Option"},
                        {"value":"value2", "selected":"false", "text":"Second Option"},
                        {"value":"value3", "selected":"false", "text":"Third Option"} ]

            }},
            {"personselector":{
                "name":"person-selector-name",
                "placeholder":"example-placeholder",
                "required":"true"
            }},
            {"table_select":{
                    "select":{
                        "position":"right",
                        "type":"checkbox"
                    },
                    "header_list": ["H1", "H2", "H3"],
                    "body": [["A1", "B1", "C1"],
                             ["A2", "B2", "C2"],
                             ["A3", "B3", "C3"]],
                    "footer_list": ["F1", "F2", "F3"]
                    }}],
    "footer" : [
        {"button": {
            "name": "example-button",
            "type": "action",
            "text": "Submit"
        }},
        {"button": {
            "name": "example-button",
            "type": "reset",
            "text": "Cancel"
        }}],
    "form": ""

}

Render using:

SmsRenderer.renderForm(form_data, smsTypes['FORM'])

The output of the above function is:

<messageML>
  <form id="test_form_id">
    <h4>Test Form</h4>
    <text-field name="exmaple-text-field" placeholder="example-placeholder" required="true" masked="true" minlength="1" maxlength="128"></text-field>
    <textarea name="exmaple-text-area" placeholder="example-placeholder" required="true"></textarea>
    <checkbox name="example-name" value="example-value" checked="false">Red</checkbox>
    <select name="dropdown-name" required="true">
          <option value="value1" selected="true">First Option</option>
          <option value="value2" selected="false">Second Option</option>
          <option value="value3" selected="false">Third Option</option>
    </select>
    <person-selector name="person-selector-name" placeholder="example-placeholder" required="true"/>
    <table>
      <thead>
        <tr><td>H1</td><td>H2</td><td>H3</td><td><input type="checkbox" name="tablesel-header" /></td></tr>
      </thead>
      <tbody>
        <tr><td>A1</td><td>B1</td><td>C1</td><td><input type="checkbox" name="tablesel-header" /></td></tr><tr><td>A2</td><td>B2</td><td>C2</td><td><input type="checkbox" name="tablesel-header" /></td></tr><tr><td>A3</td><td>B3</td><td>C3</td><td><input type="checkbox" name="tablesel-header" /></td></tr>
      </tbody>
      <tfoot>
        <tr><td>F1</td><td>F2</td><td>F3</td><td><input type="checkbox" name="tablesel-header" /></td></tr>
      </tfoot>
    </table>
    <button name="example-button" type="action"> Submit</button>
    <button name="example-button" type="reset"> Cancel</button>
  </form>
</messageML>

In the client application

  • In the code, in the render function of the entity service, compile your message using the command:
compiledMessage = SmsRenderer.renderInApp(myMessageData, SmsRenderer.smsTypes.ALERT);
  • In the same render method, return the message like that:
return {
    template: compiledMessage
};

SDK API

Template type names are accessible by SmsRenderer.smsTypes constant, like so:

simpleMessageTemplate = SmsRenderer.smsTypes.SIMPLE;

Possible values are SIMPLE, ALERT, INFORMATION, NOTIFICATION, TABLE, LIST_TEMPLATE, BUTTON, TEXTFIELD, CHECKBOX, TEXTAREA, RADIOBUTTON, PERSONSELECTOR, DROPDOWN_MENU, TABLE_SELECT.

To get the compiled template in MessageML format, use the functions:

Syntax Parameters Where to use
SmsRenderer.renderInApp() messageData, messageType Extension application
SmsRenderer.renderInBot() messageData, messageType Bot
SmsRenderer.renderForm() messageData, messageType Bot

The complete list of message data object properties can be seen in the test examples:

Metadata

Release files for sms-sdk-renderer-python 0.1.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sms-sdk-renderer-python 0.1.8
File Size Uploaded
sms_sdk_renderer_python-0.1.8.tar.gz 6.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sms-sdk-renderer-python 0.1.8
File Interpreter ABI Platform
sms_sdk_renderer_python-0.1.8-py3-none-any.whl Python 3 none any Details

Total release size: 21.4 kB

Release files / sms_sdk_renderer_python-0.1.8.tar.gz

Download URL sms_sdk_renderer_python-0.1.8.tar.gz
Size 6.4 kB
Tags Source
SHA-256 checksum
How to use checksums
2794d2169b207764856677b80a4fee6b398b81a3e027afed8704a8a5205bb6ab
BLAKE2b-256 checksum
How to use checksums
d77012ddea138e1e6a1b293c69f4fa543ce01389b9baea43e49f7b108c5d16ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

Release files / sms_sdk_renderer_python-0.1.8-py3-none-any.whl

Download URL sms_sdk_renderer_python-0.1.8-py3-none-any.whl
Size 15.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
19067dacb735c7cf9aad93f212cf6dda2a629f0952e52b6e16109b7ecdbcbe9c
BLAKE2b-256 checksum
How to use checksums
166b506228c1773760ee0293b6ed6790fd6d87bb47e698bf506f447863ecb091
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

Release history Release notifications | RSS feed

This release

0.1.8 This release

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page