From 1aa8c2cffc1e9c9403b94d22c0f44ca70c40c555 Mon Sep 17 00:00:00 2001
From: Olle Johansson <oej@edvina.net>
Date: Tue, 31 Oct 2006 10:42:22 +0000
Subject: [PATCH] Add manager sendtext action. (Issue 6131, ZX81 - thanks!)

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@46630 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 main/manager.c | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/main/manager.c b/main/manager.c
index a2d146c42d..0b87cdb554 100644
--- a/main/manager.c
+++ b/main/manager.c
@@ -1429,6 +1429,45 @@ static int action_status(struct mansession *s, struct message *m)
 	return 0;
 }
 
+static char mandescr_sendtext[] =
+"Description: Sends A Text Message while in a call.\n"
+"Variables: (Names marked with * are required)\n"
+"       *Channel: Channel to send message to\n"
+"       *Message: Message to send\n"
+"       ActionID: Optional Action id for message matching.\n";
+
+static int action_sendtext(struct mansession *s, struct message *m)
+{
+	struct ast_channel *c = NULL;
+	char *name = astman_get_header(m, "Channel");
+	char *textmsg = astman_get_header(m, "Message");
+	int res = 0;
+
+	if (!ast_strlen_zero(name)) {
+		astman_send_error(s, m, "No channel specified");
+		return 0;
+	}
+	if (!ast_strlen_zero(textmsg)) {
+		astman_send_error(s, m, "No Message specified");
+		return 0;
+	}
+
+	c = ast_get_channel_by_name_locked(name);
+	if (!c) {
+		astman_send_error(s, m, "No such channel");
+		return 0;
+	}
+
+	ast_mutex_unlock(&c->lock);
+	res = ast_sendtext(c, textmsg);
+	if (res > 0) {
+		astman_send_ack(s, m, "Success");
+	} else {
+		astman_send_error(s, m, "Failure");
+	}
+	return res;
+}
+
 static char mandescr_redirect[] =
 "Description: Redirect (transfer) a call.\n"
 "Variables: (Names marked with * are required)\n"
@@ -2761,6 +2800,7 @@ int init_manager(void)
 		ast_manager_register2("MailboxStatus", EVENT_FLAG_CALL, action_mailboxstatus, "Check Mailbox", mandescr_mailboxstatus );
 		ast_manager_register2("MailboxCount", EVENT_FLAG_CALL, action_mailboxcount, "Check Mailbox Message Count", mandescr_mailboxcount );
 		ast_manager_register2("ListCommands", 0, action_listcommands, "List available manager commands", mandescr_listcommands);
+		ast_manager_register2("SendText", EVENT_FLAG_CALL, action_sendtext, "Send text message to channel", mandescr_sendtext);
 		ast_manager_register2("UserEvent", EVENT_FLAG_USER, action_userevent, "Send an arbitrary event", mandescr_userevent);
 		ast_manager_register2("WaitEvent", 0, action_waitevent, "Wait for an event to occur", mandescr_waitevent);
 
-- 
GitLab