mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-03 11:25:35 +00:00
message & stasis/messaging: make text message variables work in ARI
When a text message was received any associated variable was not written to the ARI TextMessageReceived event. This occurred because Asterisk only wrote out "send" variables. However, even those "send" variables would fail ARI validation due to a TextMessageVariable formatting bug. Since it seems the TextMessageReceived event has never been able to include actual variables it was decided to remove the TextMessageVariable object type from ARI, and simply return a JSON object of key/value pairs for variables. This aligns more with how the ARI sendMessage handles variables, and other places in ARI. ASTERISK-28755 #close Change-Id: Ia6051c01a53b30cf7edef84c27df4ed4479b8b6f
This commit is contained in:
@@ -939,9 +939,8 @@ int ast_ari_validate_text_message(struct ast_json *json)
|
||||
} else
|
||||
if (strcmp("variables", ast_json_object_iter_key(iter)) == 0) {
|
||||
int prop_is_valid;
|
||||
prop_is_valid = ast_ari_validate_list(
|
||||
ast_json_object_iter_value(iter),
|
||||
ast_ari_validate_text_message_variable);
|
||||
prop_is_valid = ast_ari_validate_object(
|
||||
ast_json_object_iter_value(iter));
|
||||
if (!prop_is_valid) {
|
||||
ast_log(LOG_ERROR, "ARI TextMessage field variables failed validation\n");
|
||||
res = 0;
|
||||
@@ -978,60 +977,6 @@ ari_validator ast_ari_validate_text_message_fn(void)
|
||||
return ast_ari_validate_text_message;
|
||||
}
|
||||
|
||||
int ast_ari_validate_text_message_variable(struct ast_json *json)
|
||||
{
|
||||
int res = 1;
|
||||
struct ast_json_iter *iter;
|
||||
int has_key = 0;
|
||||
int has_value = 0;
|
||||
|
||||
for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
|
||||
if (strcmp("key", ast_json_object_iter_key(iter)) == 0) {
|
||||
int prop_is_valid;
|
||||
has_key = 1;
|
||||
prop_is_valid = ast_ari_validate_string(
|
||||
ast_json_object_iter_value(iter));
|
||||
if (!prop_is_valid) {
|
||||
ast_log(LOG_ERROR, "ARI TextMessageVariable field key failed validation\n");
|
||||
res = 0;
|
||||
}
|
||||
} else
|
||||
if (strcmp("value", ast_json_object_iter_key(iter)) == 0) {
|
||||
int prop_is_valid;
|
||||
has_value = 1;
|
||||
prop_is_valid = ast_ari_validate_string(
|
||||
ast_json_object_iter_value(iter));
|
||||
if (!prop_is_valid) {
|
||||
ast_log(LOG_ERROR, "ARI TextMessageVariable field value failed validation\n");
|
||||
res = 0;
|
||||
}
|
||||
} else
|
||||
{
|
||||
ast_log(LOG_ERROR,
|
||||
"ARI TextMessageVariable has undocumented field %s\n",
|
||||
ast_json_object_iter_key(iter));
|
||||
res = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!has_key) {
|
||||
ast_log(LOG_ERROR, "ARI TextMessageVariable missing required field key\n");
|
||||
res = 0;
|
||||
}
|
||||
|
||||
if (!has_value) {
|
||||
ast_log(LOG_ERROR, "ARI TextMessageVariable missing required field value\n");
|
||||
res = 0;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
ari_validator ast_ari_validate_text_message_variable_fn(void)
|
||||
{
|
||||
return ast_ari_validate_text_message_variable;
|
||||
}
|
||||
|
||||
int ast_ari_validate_caller_id(struct ast_json *json)
|
||||
{
|
||||
int res = 1;
|
||||
|
@@ -387,24 +387,6 @@ int ast_ari_validate_text_message(struct ast_json *json);
|
||||
*/
|
||||
ari_validator ast_ari_validate_text_message_fn(void);
|
||||
|
||||
/*!
|
||||
* \brief Validator for TextMessageVariable.
|
||||
*
|
||||
* A key/value pair variable in a text message.
|
||||
*
|
||||
* \param json JSON object to validate.
|
||||
* \returns True (non-zero) if valid.
|
||||
* \returns False (zero) if invalid.
|
||||
*/
|
||||
int ast_ari_validate_text_message_variable(struct ast_json *json);
|
||||
|
||||
/*!
|
||||
* \brief Function pointer to ast_ari_validate_text_message_variable().
|
||||
*
|
||||
* See \ref ast_ari_model_validators.h for more details.
|
||||
*/
|
||||
ari_validator ast_ari_validate_text_message_variable_fn(void);
|
||||
|
||||
/*!
|
||||
* \brief Validator for CallerID.
|
||||
*
|
||||
@@ -1497,10 +1479,7 @@ ari_validator ast_ari_validate_application_fn(void);
|
||||
* - body: string (required)
|
||||
* - from: string (required)
|
||||
* - to: string (required)
|
||||
* - variables: List[TextMessageVariable]
|
||||
* TextMessageVariable
|
||||
* - key: string (required)
|
||||
* - value: string (required)
|
||||
* - variables: object
|
||||
* CallerID
|
||||
* - name: string (required)
|
||||
* - number: string (required)
|
||||
|
Reference in New Issue
Block a user