mirror of
https://github.com/matrix-org/matrix-hookshot.git
synced 2025-03-10 21:19:13 +00:00
Generic webhook transform: allow specifying msgtype (#282)
* Generic webhook transform: allow specifying msgtype * Update doc and changelog for msgtype webhook transform
This commit is contained in:
parent
8f22f0d851
commit
7379346fc1
1
changelog.d/282.feature
Normal file
1
changelog.d/282.feature
Normal file
@ -0,0 +1 @@
|
||||
Allow specifying msgtype for generic webhook transformations.
|
@ -109,6 +109,7 @@ The `v2` api expects an object to be returned from the `result` variable.
|
||||
"empty": true|false, // Should the webhook be ignored and no output returned. The default is false (plain must be provided).
|
||||
"plain": "Some text", // The plaintext value to be used for the Matrix message.
|
||||
"html": "<b>Some</b> text", // The HTML value to be used for the Matrix message. If not provided, plain will be interpreted as markdown.
|
||||
"msgtype": "some.type", // The message type, such as m.notice or m.text, to be used for the Matrix message. If not provided, m.notice will be used.
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -47,6 +47,7 @@ interface WebhookTransformationResult {
|
||||
version: string;
|
||||
plain?: string;
|
||||
html?: string;
|
||||
msgtype?: string;
|
||||
empty?: boolean;
|
||||
}
|
||||
|
||||
@ -220,7 +221,7 @@ export class GenericHookConnection extends BaseConnection implements IConnection
|
||||
return msg;
|
||||
}
|
||||
|
||||
public executeTransformationFunction(data: unknown): {plain: string, html?: string}|null {
|
||||
public executeTransformationFunction(data: unknown): {plain: string, html?: string, msgtype?: string}|null {
|
||||
if (!this.transformationFunction) {
|
||||
throw Error('Transformation function not defined');
|
||||
}
|
||||
@ -258,10 +259,14 @@ export class GenericHookConnection extends BaseConnection implements IConnection
|
||||
if (transformationResult.html && typeof transformationResult.html !== "string") {
|
||||
throw Error("Result returned from transformation didn't provide a string value for html");
|
||||
}
|
||||
if (transformationResult.msgtype && typeof transformationResult.msgtype !== "string") {
|
||||
throw Error("Result returned from transformation didn't provide a string value for msgtype");
|
||||
}
|
||||
|
||||
return {
|
||||
plain: plain,
|
||||
html: transformationResult.html,
|
||||
msgtype: transformationResult.msgtype,
|
||||
}
|
||||
}
|
||||
|
||||
@ -272,7 +277,7 @@ export class GenericHookConnection extends BaseConnection implements IConnection
|
||||
*/
|
||||
public async onGenericHook(data: unknown): Promise<boolean> {
|
||||
log.info(`onGenericHook ${this.roomId} ${this.hookId}`);
|
||||
let content: {plain: string, html?: string};
|
||||
let content: {plain: string, html?: string, msgtype?: string};
|
||||
let success = true;
|
||||
if (!this.transformationFunction) {
|
||||
content = this.transformHookData(data);
|
||||
@ -295,7 +300,7 @@ export class GenericHookConnection extends BaseConnection implements IConnection
|
||||
await this.ensureDisplayname();
|
||||
|
||||
await this.messageClient.sendMatrixMessage(this.roomId, {
|
||||
msgtype: "m.notice",
|
||||
msgtype: content.msgtype || "m.notice",
|
||||
body: content.plain,
|
||||
formatted_body: content.html || md.renderInline(content.plain),
|
||||
format: "org.matrix.custom.html",
|
||||
|
Loading…
x
Reference in New Issue
Block a user