Skip to content

Commit 54761a4

Browse files
InterLinked1jcolp
authored andcommitted
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
1 parent 8ec13f0 commit 54761a4

File tree

2 files changed

+88
-3
lines changed

2 files changed

+88
-3
lines changed

apps/app_sendtext.c

Lines changed: 84 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* \brief App to transmit a text message
2222
*
2323
* \author Mark Spencer <markster@digium.com>
24+
* \author Naveen Albert <asterisk@phreaknet.org>
2425
*
2526
* \note Requires support of sending text messages from channel driver
2627
*
@@ -140,11 +141,50 @@
140141
<see-also>
141142
<ref type="application">SendImage</ref>
142143
<ref type="application">SendURL</ref>
144+
<ref type="application">ReceiveText</ref>
145+
</see-also>
146+
</application>
147+
<application name="ReceiveText" language="en_US">
148+
<synopsis>
149+
Receive a Text Message on a channel.
150+
</synopsis>
151+
<syntax>
152+
<parameter name="timeout" required="false">
153+
<para>Time in seconds to wait for text. Default is 0 (forever).</para>
154+
</parameter>
155+
</syntax>
156+
<description>
157+
<para>Waits for <replaceable>timeout</replaceable> seconds on the current channel
158+
to receive text.</para>
159+
<para>Result of transmission will be stored in the following variables:</para>
160+
<variablelist>
161+
<variable name="RECEIVETEXTMESSAGE">
162+
<para>The received text message.</para>
163+
</variable>
164+
<variable name="RECEIVETEXTSTATUS">
165+
<value name="SUCCESS">
166+
Transmission succeeded.
167+
</value>
168+
<value name="FAILURE">
169+
Transmission failed or timed out.
170+
</value>
171+
</variable>
172+
</variablelist>
173+
<example title="Receive message on channel">
174+
same => n,ReceiveText()
175+
same => n,NoOp(${RECEIVETEXTMESSAGE})
176+
</example>
177+
</description>
178+
<see-also>
179+
<ref type="application">SendText</ref>
180+
<ref type="application">SendImage</ref>
181+
<ref type="application">SendURL</ref>
143182
</see-also>
144183
</application>
145184
***/
146185

147186
static const char * const app = "SendText";
187+
static const char * const app2 = "ReceiveText";
148188

149189
static int sendtext_exec(struct ast_channel *chan, const char *data)
150190
{
@@ -237,14 +277,55 @@ static int sendtext_exec(struct ast_channel *chan, const char *data)
237277
return rc;
238278
}
239279

280+
static int recvtext_exec(struct ast_channel *chan, const char *data)
281+
{
282+
double timeout = 0, timeout_ms = 0;
283+
char *parse, *buf;
284+
285+
AST_DECLARE_APP_ARGS(args,
286+
AST_APP_ARG(timeout);
287+
);
288+
289+
parse = ast_strdupa(data);
290+
291+
AST_STANDARD_APP_ARGS(args, parse);
292+
293+
if (!ast_strlen_zero(args.timeout)) {
294+
if (sscanf(args.timeout, "%30lg", &timeout) != 1) {
295+
ast_log(LOG_WARNING, "Invalid timeout provided: %s. No timeout set.\n", args.timeout);
296+
return -1;
297+
}
298+
timeout_ms = timeout * 1000.0;
299+
}
300+
301+
buf = ast_recvtext(chan, timeout_ms);
302+
pbx_builtin_setvar_helper(chan, "RECEIVETEXTSTATUS", buf ? "SUCCESS" : "FAILURE");
303+
if (buf) {
304+
pbx_builtin_setvar_helper(chan, "RECEIVETEXTMESSAGE", buf);
305+
ast_free(buf);
306+
}
307+
308+
return 0;
309+
}
310+
240311
static int unload_module(void)
241312
{
242-
return ast_unregister_application(app);
313+
int res;
314+
315+
res = ast_unregister_application(app);
316+
res |= ast_unregister_application(app2);
317+
318+
return res;
243319
}
244320

245321
static int load_module(void)
246322
{
247-
return ast_register_application_xml(app, sendtext_exec);
323+
int res;
324+
325+
res = ast_register_application_xml(app, sendtext_exec);
326+
res |= ast_register_application_xml(app2, recvtext_exec);
327+
328+
return res;
248329
}
249330

250-
AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send Text Applications");
331+
AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send and Receive Text Applications");

doc/CHANGES-staging/app_sendtext.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Subject: app_sendtext
2+
3+
A ReceiveText application has been added that can be
4+
used in conjunction with the SendText application.

0 commit comments

Comments
 (0)