ソースを参照

base64 for webhook payload

kennyh 2 週間 前
コミット
8a602641b6

+ 1 - 1
apps/emqx_bridge_http/src/emqx_bridge_http.app.src

@@ -1,6 +1,6 @@
 {application, emqx_bridge_http, [
     {description, "EMQX HTTP Bridge and Connector Application"},
-    {vsn, "0.2.4"},
+    {vsn, "0.2.5"},
     {registered, []},
     {applications, [kernel, stdlib, emqx_resource, ehttpc]},
     {env, [{emqx_action_info_modules, [emqx_bridge_http_action_info]}]},

+ 8 - 1
apps/emqx_bridge_http/src/emqx_bridge_http_connector.erl

@@ -703,9 +703,16 @@ process_request(
     }.
 
 render_request_body(undefined, _, Msg) ->
+    encode_payload_with_base64(Msg),
     emqx_utils_json:encode(Msg);
 render_request_body(BodyTks, RenderTmplFunc, Msg) ->
-    RenderTmplFunc(BodyTks, Msg).
+    MsgWithBase64 = encode_payload_with_base64(Msg),
+    RenderTmplFunc(BodyTks, MsgWithBase64).
+
+encode_payload_with_base64(Msg) ->
+    Payload = maps:get(<<"payload">>, Msg, <<>>),
+    Base64Payload = base64:encode(Payload),
+    maps:put(<<"base64_payload">>, Base64Payload, Msg).
 
 render_headers(HeaderTks, RenderTmplFunc, Msg) ->
     lists:map(