Skip to content

Commit 3ad873e

Browse files
committed
js: Add convenient construction of rawPayload messages
1 parent 724e8dc commit 3ad873e

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

javascript/src/index.ts

+25
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,31 @@ class Message {
699699
}
700700
}
701701

702+
/**
703+
* Creates a `MessageIn` with the payload already being serialized.
704+
*
705+
* The payload is not normalized on the server (usually whitespace outside
706+
* of string literals, unnecessarily escaped characters in string and such
707+
* are fixed up by the server), and is not even required to be JSON.
708+
*
709+
* @param payload Serialized message payload
710+
* @param contentType Content type of the payload to send as a header. Defaults to `application/json`.
711+
*
712+
* See the class documentation for details about the other parameters.
713+
*/
714+
export function messageInRaw(eventType: string, payload: string, contentType?: string): MessageIn {
715+
let headers = contentType ? { "content-type": contentType } : undefined;
716+
717+
return {
718+
eventType,
719+
payload: {},
720+
transformationsParams: {
721+
rawPayload: payload,
722+
headers,
723+
}
724+
};
725+
}
726+
702727
class MessageAttempt {
703728
private readonly api: MessageAttemptApi;
704729

0 commit comments

Comments
 (0)