({
bridge,
config,
body,
}: {
bridge: Bridge;
config: IConfig;
body: ILinenMatrixPayload;
})
| 5 | const log = new Logger('linen-bridge:webhook'); |
| 6 | |
| 7 | export async function handleLinenEvent({ |
| 8 | bridge, |
| 9 | config, |
| 10 | body, |
| 11 | }: { |
| 12 | bridge: Bridge; |
| 13 | config: IConfig; |
| 14 | body: ILinenMatrixPayload; |
| 15 | }) { |
| 16 | try { |
| 17 | const intent = bridge.getIntent( |
| 18 | `@linen_${body.user}:${config.matrix.domain}` |
| 19 | ); |
| 20 | |
| 21 | if (body.threadId) { |
| 22 | // it means is a reply |
| 23 | const { event_id } = await intent.sendMessage(body.channelId, { |
| 24 | body: body.body, |
| 25 | msgtype: 'm.text', |
| 26 | ['m.relates_to']: { |
| 27 | event_id: body.threadId, |
| 28 | rel_type: 'm.thread', |
| 29 | }, |
| 30 | }); |
| 31 | return { status: 200, ok: true, event_id }; |
| 32 | } else { |
| 33 | // otherwise is a new message |
| 34 | const { event_id } = await intent.sendText(body.channelId, body.body); |
| 35 | return { status: 200, ok: true, event_id }; |
| 36 | } |
| 37 | } catch (error) { |
| 38 | log.error(error); |
| 39 | return { status: 500, ok: false }; |
| 40 | } |
| 41 | } |
no test coverage detected