[Asterisk-code-review] app_sendtext: Add ReceiveText application (asterisk[19])

N A asteriskteam at digium.com
Mon Dec 13 07:42:40 CST 2021


N A has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/17672 )


Change subject: app_sendtext: Add ReceiveText application
......................................................................

app_sendtext: Add ReceiveText application

Adds a ReceiveText application that can be used in
conjunction with SendText. Currently, there is no
way in Asterisk to receive text in the dialplan
(or anywhere else, really). This allows for Asterisk
to be the recipient of text instead of just the sender.

ASTERISK-29759 #close

Change-Id: Ica2c354a42bff69f323a0493d3a7cd0fb129d52d
---
M apps/app_sendtext.c
A doc/CHANGES-staging/app_sendtext.txt
2 files changed, 88 insertions(+), 3 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/72/17672/1

diff --git a/apps/app_sendtext.c b/apps/app_sendtext.c
index 45ae073..07e6acc 100644
--- a/apps/app_sendtext.c
+++ b/apps/app_sendtext.c
@@ -21,6 +21,7 @@
  * \brief App to transmit a text message
  *
  * \author Mark Spencer <markster at digium.com>
+ * \author Naveen Albert <asterisk at phreaknet.org>
  *
  * \note Requires support of sending text messages from channel driver
  *
@@ -140,11 +141,50 @@
 		<see-also>
 			<ref type="application">SendImage</ref>
 			<ref type="application">SendURL</ref>
+			<ref type="application">ReceiveText</ref>
+		</see-also>
+	</application>
+	<application name="ReceiveText" language="en_US">
+		<synopsis>
+			Receive a Text Message on a channel.
+		</synopsis>
+		<syntax>
+			<parameter name="timeout" required="false">
+				<para>Time in seconds to wait for text. Default is 0 (forever).</para>
+			</parameter>
+		</syntax>
+		<description>
+			<para>Waits for <replaceable>timeout</replaceable> seconds on the current channel
+			to receive text.</para>
+			<para>Result of transmission will be stored in the following variables:</para>
+			<variablelist>
+				<variable name="RECEIVETEXTMESSAGE">
+					<para>The received text message.</para>
+				</variable>
+				<variable name="RECEIVETEXTSTATUS">
+					<value name="SUCCESS">
+						Transmission succeeded.
+					</value>
+					<value name="FAILURE">
+						Transmission failed or timed out.
+					</value>
+				</variable>
+			</variablelist>
+			<example title="Receive message on channel">
+			 same => n,ReceiveText()
+			 same => n,NoOp(${RECEIVETEXTMESSAGE})
+			</example>
+		</description>
+		<see-also>
+			<ref type="application">SendText</ref>
+			<ref type="application">SendImage</ref>
+			<ref type="application">SendURL</ref>
 		</see-also>
 	</application>
  ***/
 
 static const char * const app = "SendText";
+static const char * const app2 = "ReceiveText";
 
 static int sendtext_exec(struct ast_channel *chan, const char *data)
 {
@@ -237,14 +277,55 @@
 	return rc;
 }
 
+static int recvtext_exec(struct ast_channel *chan, const char *data)
+{
+	double timeout = 0, timeout_ms = 0;
+	char *parse, *buf;
+
+	AST_DECLARE_APP_ARGS(args,
+		AST_APP_ARG(timeout);
+	);
+
+	parse = ast_strdupa(data);
+
+	AST_STANDARD_APP_ARGS(args, parse);
+
+	if (!ast_strlen_zero(args.timeout)) {
+		if (sscanf(args.timeout, "%30lg", &timeout) != 1) {
+			ast_log(LOG_WARNING, "Invalid timeout provided: %s. No timeout set.\n", args.timeout);
+			return -1;
+		}
+		timeout_ms = timeout * 1000.0;
+	}
+
+	buf = ast_recvtext(chan, timeout_ms);
+	pbx_builtin_setvar_helper(chan, "RECEIVETEXTSTATUS", buf ? "SUCCESS" : "FAILURE");
+	if (buf) {
+		pbx_builtin_setvar_helper(chan, "RECEIVETEXTMESSAGE", buf);
+		ast_free(buf);
+	}
+
+	return 0;
+}
+
 static int unload_module(void)
 {
-	return ast_unregister_application(app);
+	int res;
+	
+	res = ast_unregister_application(app);
+	res |= ast_unregister_application(app2);
+
+	return res;
 }
 
 static int load_module(void)
 {
-	return ast_register_application_xml(app, sendtext_exec);
+	int res;
+
+	res = ast_register_application_xml(app, sendtext_exec);
+	res |= ast_register_application_xml(app2, recvtext_exec);
+
+	return res;
 }
 
-AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send Text Applications");
+AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send and Receive Text Applications");
diff --git a/doc/CHANGES-staging/app_sendtext.txt b/doc/CHANGES-staging/app_sendtext.txt
new file mode 100644
index 0000000..37dd64b
--- /dev/null
+++ b/doc/CHANGES-staging/app_sendtext.txt
@@ -0,0 +1,4 @@
+Subject: app_sendtext
+
+A ReceiveText application has been added that can be
+used in conjunction with the SendText application.

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/17672
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 19
Gerrit-Change-Id: Ica2c354a42bff69f323a0493d3a7cd0fb129d52d
Gerrit-Change-Number: 17672
Gerrit-PatchSet: 1
Gerrit-Owner: N A <mail at interlinked.x10host.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20211213/fdc43387/attachment.html>


More information about the asterisk-code-review mailing list