<p>George Joseph has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/8764">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">app_sendtext:  Enhance SendText to support Enhanced Messaging<br><br>SendText now accepts new channel variables that can be used<br>to override the To and From display names and set the Content-Type<br>of a message.  Since you can now set Content-Type, other text/*<br>content types are now valid.<br><br>Change-Id: I648b4574478119f95de09d9f08e9595831b02830<br>---<br>M CHANGES<br>M apps/app_sendtext.c<br>2 files changed, 132 insertions(+), 13 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/64/8764/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/CHANGES b/CHANGES<br>index 550dcfe..5659029 100644<br>--- a/CHANGES<br>+++ b/CHANGES<br>@@ -21,6 +21,13 @@<br>    MESSAGE message from a user in a conference call, it's relayed to all<br>    other participants in the call.<br> <br>+app_sendtext<br>+------------------<br>+    Support Enhanced Messaging.  SendText now accepts new channel variables<br>+    that can be used to override the To and From display names and set the<br>+    Content-Type of a message.  Since you can now set Content-Type, other<br>+    text/* content types are now valid.<br>+<br> ------------------------------------------------------------------------------<br> --- Functionality changes from Asterisk 13.20.0 to Asterisk 13.21.0 ----------<br> ------------------------------------------------------------------------------<br>diff --git a/apps/app_sendtext.c b/apps/app_sendtext.c<br>index 3c1b4f5..6ad2f7e 100644<br>--- a/apps/app_sendtext.c<br>+++ b/apps/app_sendtext.c<br>@@ -44,15 +44,54 @@<br> /*** DOCUMENTATION<br>        <application name="SendText" language="en_US"><br>              <synopsis><br>-                     Send a Text Message.<br>+                 Send a Text Message on a channel.<br>             </synopsis><br>             <syntax><br>-                       <parameter name="text" required="true" /><br>+                  <parameter name="text" required="false" /><br>          </syntax><br>               <description><br>-                  <para>Sends <replaceable>text</replaceable> to current channel (callee).</para><br>-                      <para>Result of transmission will be stored in the <variable>SENDTEXTSTATUS</variable></para><br>+                        <para>Sends <replaceable>text</replaceable> to current channel.</para><br>+                       <note><para><literal>current channel</literal> could be the caller or callee depending<br>+                       on the context in which this application is called.</para></note><br>+                        <para><br>+                 </para><br>+                        <para>The following variables can be set:</para><br>                  <variablelist><br>+                         <variable name="SENDTEXT_FROM_DISPLAYNAME"><br>+                                  <para>If set and this channel supports enhanced messaging, this value will be<br>+                                  used as the <literal>From</literal> display name.</para><br>+                           </variable><br>+                            <variable name="SENDTEXT_TO_DISPLAYNAME"><br>+                                    <para>If set and this channel supports enhanced messaging, this value will be<br>+                                  used as the <literal>To</literal> display name.</para><br>+                             </variable><br>+                            <variable name="SENDTEXT_CONTENT_TYPE"><br>+                                      <para>If set and this channel supports enhanced messaging, this value will be<br>+                                  used as the message <literal>Content-Type</literal>.  It <emphasis>MUST</emphasis><br>+                                   be a <literal>text/&#42;</literal> content type.</para><br>+                                </variable><br>+                            <variable name="SENDTEXT_BODY"><br>+                                      <para>If set this value will be used as the message body and any text supplied<br>+                                 as a function parameter will be ignored.<br>+                                     </para><br>+                                </variable><br>+                    </variablelist><br>+                        <para><br>+                 </para><br>+                        <para>Result of transmission will be stored in the following variables:</para><br>+                   <variablelist><br>+                         <variable name="SENDTEXTTYPE"><br>+                                       <value name="NONE"><br>+                                          No message sent.<br>+                                     </value><br>+                                       <value name="BASIC"><br>+                                         Message body sent without attributes because the channel driver<br>+                                              doesn't support enhanced messaging.<br>+                                      </value><br>+                                       <value name="ENHANCED"><br>+                                              The message was sent using enhanced messaging.<br>+                                       </value><br>+                               </variable><br>                             <variable name="SENDTEXTSTATUS"><br>                                      <value name="SUCCESS"><br>                                                Transmission succeeded.<br>@@ -65,7 +104,34 @@<br>                                  </value><br>                                </variable><br>                     </variablelist><br>-                        <note><para>At this moment, text is supposed to be 7 bit ASCII in most channels.</para></note><br>+                       <para><br>+                 </para><br>+                        <note><para>The text encoding and transmission method is completely at the<br>+                       discretion of the channel driver.  chan_pjsip will use in-dialog SIP MESSAGE<br>+                 messages always.  chan_sip will use T.140 via RTP if a text media type was<br>+                   negotiated and in-dialog SIP MESSAGE messages otherwise.</para></note><br>+                   <para><br>+                 </para><br>+                        <para>Examples:<br>+                        </para><br>+                        <example title="Send a simple message"><br>+                       same => n,SendText(Your Text Here)<br>+                       </example><br>+                     <para>If the channel driver supports enhanced messaging (currently only chan_pjsip),<br>+                   you can set additional variables:</para><br>+                       <example title="Alter the From display name"><br>+                         same => n,Set(SENDTEXT_FROM_DISPLAYNAME=Really From Bob)<br>+                  same => n,SendText(Your Text Here)<br>+                       </example><br>+                     <example title="Send a JSON String"><br>+                  same => n,Set(SENDTEXT_FROM_CONTENT_TYPE=text/json)<br>+                       same => n,SendText({"foo":a, "bar":23})<br>+                      </example><br>+                     <example title="Send a JSON String (alternate)"><br>+                      same => n,Set(SENDTEXT_FROM_CONTENT_TYPE=text/json)<br>+                       same => n,Set(SENDTEXT_BODY={"foo":a, "bar":23})<br>+                      same => n,SendText()<br>+                     </example><br>              </description><br>          <see-also><br>                      <ref type="application">SendImage</ref><br>@@ -78,8 +144,13 @@<br> <br> static int sendtext_exec(struct ast_channel *chan, const char *data)<br> {<br>-     char *status = "UNSUPPORTED";<br>+      char *status;<br>+        char *msg_type;<br>       struct ast_str *str;<br>+ const char *from;<br>+    const char *to;<br>+      const char *content_type;<br>+    const char *body;<br> <br>  /* NOT ast_strlen_zero, because some protocols (e.g. SIP) MUST be able to<br>      * send a zero-length message. */<br>@@ -95,17 +166,58 @@<br>       ast_str_get_encoded_str(&str, -1, data);<br> <br>       ast_channel_lock(chan);<br>-      if (!ast_channel_tech(chan)->send_text) {<br>-         ast_channel_unlock(chan);<br>-            /* Does not support transport */<br>-             pbx_builtin_setvar_helper(chan, "SENDTEXTSTATUS", status);<br>-         return 0;<br>+    from = pbx_builtin_getvar_helper(chan, "SENDTEXT_FROM_DISPLAYNAME");<br>+       to = pbx_builtin_getvar_helper(chan, "SENDTEXT_TO_DISPLAYNAME");<br>+   content_type = pbx_builtin_getvar_helper(chan, "SENDTEXT_CONTENT_TYPE");<br>+   body = pbx_builtin_getvar_helper(chan, "SENDTEXT_BODY");<br>+   if (!body) {<br>+         body = ast_str_buffer(str);<br>   }<br>+<br>  status = "FAILURE";<br>-        if (!ast_sendtext(chan, ast_str_buffer(str))) {<br>-              status = "SUCCESS";<br>+        msg_type = "NONE";<br>+ if (ast_channel_tech(chan)->send_text_data) {<br>+             struct ast_msg_data *msg;<br>+            struct ast_msg_data_attribute attrs[] =<br>+              {<br>+                    {<br>+                            .type = AST_MSG_DATA_ATTR_FROM,<br>+                              .value = (char *)S_OR(from, ""),<br>+                   },<br>+                   {<br>+                            .type = AST_MSG_DATA_ATTR_TO,<br>+                                .value = (char *)S_OR(to, ""),<br>+                     },<br>+                   {<br>+                            .type = AST_MSG_DATA_ATTR_CONTENT_TYPE,<br>+                              .value = (char *)S_OR(content_type, ""),<br>+                   },<br>+                   {<br>+                            .type = AST_MSG_DATA_ATTR_BODY,<br>+                              .value = (char *)S_OR(body, ""),<br>+                   },<br>+           };<br>+<br>+                msg_type = "ENHANCED";<br>+             msg = ast_msg_data_alloc(AST_MSG_DATA_SOURCE_TYPE_IN_DIALOG, attrs, ARRAY_LEN(attrs));<br>+               if (msg) {<br>+                   if (ast_sendtext_data(chan, msg) == 0) {<br>+                             status = "SUCCESS";<br>+                        }<br>+                    ast_free(msg);<br>+               }<br>+    } else if(ast_channel_tech(chan)->send_text) {<br>+            msg_type = "BASIC";<br>+                if (ast_sendtext(chan, body) == 0) {<br>+                 status = "SUCCESS";<br>+                }<br>+    } else {<br>+             msg_type = "NONE";<br>+         status = "UNSUPPORTED";<br>     }<br>+<br>  ast_channel_unlock(chan);<br>+    pbx_builtin_setvar_helper(chan, "SENDTEXTTYPE", msg_type);<br>  pbx_builtin_setvar_helper(chan, "SENDTEXTSTATUS", status);<br>  return 0;<br> }<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/8764">change 8764</a>. To unsubscribe, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/8764"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I648b4574478119f95de09d9f08e9595831b02830 </div>
<div style="display:none"> Gerrit-Change-Number: 8764 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: George Joseph <gjoseph@digium.com> </div>