fix: remove the default value of webhook body field
This commit is contained in:
parent
3859878985
commit
724015af47
|
@ -93,11 +93,20 @@ HTTP 请求的标头。<br/>
|
|||
desc {
|
||||
en: """
|
||||
The body of the HTTP request.<br/>
|
||||
If not provided, the body will be a JSON object of all the available fields.<br/>
|
||||
There, 'all the available fields' means the context of a MQTT message when
|
||||
this webhook is triggered by receiving a MQTT message (the `local_topic` is set),
|
||||
or the context of the event when this webhook is triggered by a rule (i.e. this
|
||||
webhook is used as an action of a rule).<br/>
|
||||
Template with variables is allowed.
|
||||
"""
|
||||
zh: """
|
||||
HTTP 请求的正文。<br/>
|
||||
允许使用带有变量的模板。"""
|
||||
如果没有设置该字段,请求正文将是包含所有可用字段的 JSON object。<br/>
|
||||
如果该 webhook 是由于收到 MQTT 消息触发的,'所有可用字段' 将是 MQTT 消息的
|
||||
上下文信息;如果该 webhook 是由于规则触发的,'所有可用字段' 则为触发事件的上下文信息。<br/>
|
||||
允许使用带有变量的模板。
|
||||
"""
|
||||
}
|
||||
label: {
|
||||
en: "HTTP Body"
|
||||
|
|
|
@ -274,7 +274,6 @@ parse_confs(
|
|||
#{
|
||||
url := Url,
|
||||
method := Method,
|
||||
body := Body,
|
||||
headers := Headers,
|
||||
request_timeout := ReqTimeout,
|
||||
max_retries := Retry
|
||||
|
@ -288,7 +287,7 @@ parse_confs(
|
|||
#{
|
||||
path => Path,
|
||||
method => Method,
|
||||
body => Body,
|
||||
body => maps:get(body, Conf, undefined),
|
||||
headers => Headers,
|
||||
request_timeout => ReqTimeout,
|
||||
max_retries => Retry
|
||||
|
|
|
@ -115,7 +115,7 @@ request_config() ->
|
|||
mk(
|
||||
binary(),
|
||||
#{
|
||||
default => <<"${payload}">>,
|
||||
default => undefined,
|
||||
desc => ?DESC("config_body")
|
||||
}
|
||||
)},
|
||||
|
|
|
@ -431,14 +431,13 @@ preprocess_request(
|
|||
#{
|
||||
method := Method,
|
||||
path := Path,
|
||||
body := Body,
|
||||
headers := Headers
|
||||
} = Req
|
||||
) ->
|
||||
#{
|
||||
method => emqx_plugin_libs_rule:preproc_tmpl(bin(Method)),
|
||||
path => emqx_plugin_libs_rule:preproc_tmpl(Path),
|
||||
body => emqx_plugin_libs_rule:preproc_tmpl(Body),
|
||||
body => maybe_preproc_tmpl(body, Req),
|
||||
headers => preproc_headers(Headers),
|
||||
request_timeout => maps:get(request_timeout, Req, 30000),
|
||||
max_retries => maps:get(max_retries, Req, 2)
|
||||
|
@ -469,6 +468,12 @@ preproc_headers(Headers) when is_list(Headers) ->
|
|||
Headers
|
||||
).
|
||||
|
||||
maybe_preproc_tmpl(Key, Conf) ->
|
||||
case maps:get(Key, Conf, undefined) of
|
||||
undefined -> undefined;
|
||||
Val -> emqx_plugin_libs_rule:preproc_tmpl(Val)
|
||||
end.
|
||||
|
||||
process_request(
|
||||
#{
|
||||
method := MethodTks,
|
||||
|
@ -487,7 +492,7 @@ process_request(
|
|||
request_timeout => ReqTimeout
|
||||
}.
|
||||
|
||||
process_request_body([], Msg) ->
|
||||
process_request_body(undefined, Msg) ->
|
||||
emqx_json:encode(Msg);
|
||||
process_request_body(BodyTks, Msg) ->
|
||||
emqx_plugin_libs_rule:proc_tmpl(BodyTks, Msg).
|
||||
|
|
Loading…
Reference in New Issue