mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-20 20:44:20 +00:00
Implement ARI POST to /channels, to originate a call.
(closes issue ASTERISK-21617) Review: https://reviewboard.asterisk.org/r/2597/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@390885 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -83,6 +83,18 @@ static void stasis_http_originate_cb(
|
|||||||
if (strcmp(i->name, "context") == 0) {
|
if (strcmp(i->name, "context") == 0) {
|
||||||
args.context = (i->value);
|
args.context = (i->value);
|
||||||
} else
|
} else
|
||||||
|
if (strcmp(i->name, "callerId") == 0) {
|
||||||
|
args.caller_id = (i->value);
|
||||||
|
} else
|
||||||
|
if (strcmp(i->name, "timeout") == 0) {
|
||||||
|
args.timeout = atoi(i->value);
|
||||||
|
} else
|
||||||
|
if (strcmp(i->name, "app") == 0) {
|
||||||
|
args.app = (i->value);
|
||||||
|
} else
|
||||||
|
if (strcmp(i->name, "appArgs") == 0) {
|
||||||
|
args.app_args = (i->value);
|
||||||
|
} else
|
||||||
{}
|
{}
|
||||||
}
|
}
|
||||||
stasis_http_originate(headers, &args, response);
|
stasis_http_originate(headers, &args, response);
|
||||||
|
@@ -33,6 +33,8 @@
|
|||||||
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
||||||
|
|
||||||
#include "asterisk/file.h"
|
#include "asterisk/file.h"
|
||||||
|
#include "asterisk/pbx.h"
|
||||||
|
#include "asterisk/callerid.h"
|
||||||
#include "asterisk/stasis_app.h"
|
#include "asterisk/stasis_app.h"
|
||||||
#include "asterisk/stasis_app_playback.h"
|
#include "asterisk/stasis_app_playback.h"
|
||||||
#include "asterisk/stasis_channels.h"
|
#include "asterisk/stasis_channels.h"
|
||||||
@@ -314,10 +316,69 @@ void stasis_http_originate(struct ast_variable *headers,
|
|||||||
struct ast_originate_args *args,
|
struct ast_originate_args *args,
|
||||||
struct stasis_http_response *response)
|
struct stasis_http_response *response)
|
||||||
{
|
{
|
||||||
if (args->endpoint) {
|
const char *dialtech = NULL;
|
||||||
ast_log(LOG_DEBUG, "Dialing specific endpoint %s\n", args->endpoint);
|
char dialdevice[AST_CHANNEL_NAME];
|
||||||
|
char *caller_id = NULL;
|
||||||
|
char *cid_num = NULL;
|
||||||
|
char *cid_name = NULL;
|
||||||
|
int timeout = 30000;
|
||||||
|
|
||||||
|
const char *app = "Stasis";
|
||||||
|
RAII_VAR(struct ast_str *, appdata, ast_str_create(64), ast_free);
|
||||||
|
|
||||||
|
if (!appdata) {
|
||||||
|
stasis_http_response_alloc_failed(response);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ast_log(LOG_DEBUG, "Dialing %s@%s\n", args->extension, args->context);
|
ast_str_set(&appdata, 0, "%s", args->app);
|
||||||
/* ast_pbx_outgoing_app - originates a channel, putting it into an application */
|
if (!ast_strlen_zero(args->app_args)) {
|
||||||
|
ast_str_append(&appdata, 0, ",%s", args->app_args);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args->timeout > 0) {
|
||||||
|
timeout = args->timeout * 1000;
|
||||||
|
} else if (args->timeout == -1) {
|
||||||
|
timeout = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ast_strlen_zero(args->endpoint)) {
|
||||||
|
char *tmp = ast_strdupa(args->endpoint);
|
||||||
|
char *stuff;
|
||||||
|
|
||||||
|
if ((stuff = strchr(tmp, '/'))) {
|
||||||
|
*stuff++ = '\0';
|
||||||
|
dialtech = tmp;
|
||||||
|
ast_copy_string(dialdevice, stuff, sizeof(dialdevice));
|
||||||
|
}
|
||||||
|
} else if (!ast_strlen_zero(args->extension) && !ast_strlen_zero(args->context)) {
|
||||||
|
dialtech = "Local";
|
||||||
|
snprintf(dialdevice, sizeof(dialdevice), "%s@%s", args->extension, args->context);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ast_strlen_zero(dialtech) || ast_strlen_zero(dialdevice)) {
|
||||||
|
stasis_http_response_error(
|
||||||
|
response, 500, "Internal server error",
|
||||||
|
"Invalid endpoint or extension and context specified");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ast_strlen_zero(args->caller_id)) {
|
||||||
|
caller_id = ast_strdupa(args->caller_id);
|
||||||
|
ast_callerid_parse(caller_id, &cid_name, &cid_num);
|
||||||
|
|
||||||
|
if (ast_is_shrinkable_phonenumber(cid_num)) {
|
||||||
|
ast_shrink_phone_number(cid_num);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ast_debug(1, "Dialing %s/%s\n", dialtech, dialdevice);
|
||||||
|
|
||||||
|
/* originate a channel, putting it into an application */
|
||||||
|
if (ast_pbx_outgoing_app(dialtech, NULL, dialdevice, timeout, app, ast_str_buffer(appdata), NULL, 0, cid_num, cid_name, NULL, NULL, NULL)) {
|
||||||
|
stasis_http_response_alloc_failed(response);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
stasis_http_response_no_content(response);
|
||||||
}
|
}
|
||||||
|
@@ -54,10 +54,18 @@ void stasis_http_get_channels(struct ast_variable *headers, struct ast_get_chann
|
|||||||
struct ast_originate_args {
|
struct ast_originate_args {
|
||||||
/*! \brief Endpoint to call. If not specified, originate is routed via dialplan */
|
/*! \brief Endpoint to call. If not specified, originate is routed via dialplan */
|
||||||
const char *endpoint;
|
const char *endpoint;
|
||||||
/*! \brief Extension to dial */
|
/*! \brief When routing via dialplan, the extension to dial */
|
||||||
const char *extension;
|
const char *extension;
|
||||||
/*! \brief When routing via dialplan, the context use. If omitted, uses 'default' */
|
/*! \brief When routing via dialplan, the context to use. If omitted, uses 'default' */
|
||||||
const char *context;
|
const char *context;
|
||||||
|
/*! \brief CallerID to use when dialing the endpoint or extension. */
|
||||||
|
const char *caller_id;
|
||||||
|
/*! \brief Timeout (in seconds) before giving up dialing, or -1 for no timeout. */
|
||||||
|
int timeout;
|
||||||
|
/*! \brief Application name to pass to the Stasis application. */
|
||||||
|
const char *app;
|
||||||
|
/*! \brief Application arguments to pass to the Stasis application. */
|
||||||
|
const char *app_args;
|
||||||
};
|
};
|
||||||
/*!
|
/*!
|
||||||
* \brief Create a new channel (originate).
|
* \brief Create a new channel (originate).
|
||||||
|
@@ -40,21 +40,16 @@
|
|||||||
/*
|
/*
|
||||||
* JSON models
|
* JSON models
|
||||||
*
|
*
|
||||||
* CallerID
|
* DialplanCEP
|
||||||
* - name: string (required)
|
* - priority: long (required)
|
||||||
* - number: string (required)
|
* - exten: string (required)
|
||||||
* Dialed
|
* - context: string (required)
|
||||||
* Originated
|
|
||||||
* Playback
|
* Playback
|
||||||
* - language: string
|
* - language: string
|
||||||
* - media_uri: string (required)
|
* - media_uri: string (required)
|
||||||
* - id: string (required)
|
* - id: string (required)
|
||||||
* - target_uri: string (required)
|
* - target_uri: string (required)
|
||||||
* - state: string (required)
|
* - state: string (required)
|
||||||
* DialplanCEP
|
|
||||||
* - priority: long (required)
|
|
||||||
* - exten: string (required)
|
|
||||||
* - context: string (required)
|
|
||||||
* Channel
|
* Channel
|
||||||
* - accountcode: string (required)
|
* - accountcode: string (required)
|
||||||
* - linkedid: string (required)
|
* - linkedid: string (required)
|
||||||
@@ -71,6 +66,10 @@
|
|||||||
* - hangupsource: string (required)
|
* - hangupsource: string (required)
|
||||||
* - dialplan: DialplanCEP (required)
|
* - dialplan: DialplanCEP (required)
|
||||||
* - data: string (required)
|
* - data: string (required)
|
||||||
|
* CallerID
|
||||||
|
* - name: string (required)
|
||||||
|
* - number: string (required)
|
||||||
|
* Dialed
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#endif /* _ASTERISK_RESOURCE_CHANNELS_H */
|
#endif /* _ASTERISK_RESOURCE_CHANNELS_H */
|
||||||
|
@@ -21,7 +21,7 @@
|
|||||||
"httpMethod": "POST",
|
"httpMethod": "POST",
|
||||||
"summary": "Create a new channel (originate).",
|
"summary": "Create a new channel (originate).",
|
||||||
"nickname": "originate",
|
"nickname": "originate",
|
||||||
"responseClass": "Originated",
|
"responseClass": "void",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"name": "endpoint",
|
"name": "endpoint",
|
||||||
@@ -33,7 +33,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "extension",
|
"name": "extension",
|
||||||
"description": "Extension to dial",
|
"description": "When routing via dialplan, the extension to dial",
|
||||||
"paramType": "query",
|
"paramType": "query",
|
||||||
"required": false,
|
"required": false,
|
||||||
"allowMultiple": false,
|
"allowMultiple": false,
|
||||||
@@ -41,7 +41,40 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "context",
|
"name": "context",
|
||||||
"description": "When routing via dialplan, the context use. If omitted, uses 'default'",
|
"description": "When routing via dialplan, the context to use. If omitted, uses 'default'",
|
||||||
|
"paramType": "query",
|
||||||
|
"required": false,
|
||||||
|
"allowMultiple": false,
|
||||||
|
"dataType": "string"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "callerId",
|
||||||
|
"description": "CallerID to use when dialing the endpoint or extension.",
|
||||||
|
"paramType": "query",
|
||||||
|
"required": false,
|
||||||
|
"allowMultiple": false,
|
||||||
|
"dataType": "string"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "timeout",
|
||||||
|
"description": "Timeout (in seconds) before giving up dialing, or -1 for no timeout.",
|
||||||
|
"paramType": "query",
|
||||||
|
"required": false,
|
||||||
|
"allowMultiple": false,
|
||||||
|
"dataType": "int",
|
||||||
|
"defaultValue": 30
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "app",
|
||||||
|
"description": "Application name to pass to the Stasis application.",
|
||||||
|
"paramType": "query",
|
||||||
|
"required": true,
|
||||||
|
"allowMultiple": false,
|
||||||
|
"dataType": "string"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "appArgs",
|
||||||
|
"description": "Application arguments to pass to the Stasis application.",
|
||||||
"paramType": "query",
|
"paramType": "query",
|
||||||
"required": false,
|
"required": false,
|
||||||
"allowMultiple": false,
|
"allowMultiple": false,
|
||||||
@@ -554,10 +587,6 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"models": {
|
"models": {
|
||||||
"Originated": {
|
|
||||||
"id": "Originated",
|
|
||||||
"properties": {}
|
|
||||||
},
|
|
||||||
"Dialed": {
|
"Dialed": {
|
||||||
"id": "Dialed",
|
"id": "Dialed",
|
||||||
"properties": {}
|
"properties": {}
|
||||||
|
Reference in New Issue
Block a user