MCPcopy Create free account
hub / github.com/Linen-dev/linen.dev / handleLinenEvent

Function handleLinenEvent

packages/integration-matrix/src/handleLinenEvent.ts:7–41  ·  view source on GitHub ↗
({
  bridge,
  config,
  body,
}: {
  bridge: Bridge;
  config: IConfig;
  body: ILinenMatrixPayload;
})

Source from the content-addressed store, hash-verified

5const log = new Logger('linen-bridge:webhook');
6
7export 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}

Callers 1

index.tsFile · 0.90

Calls 2

sendMessageMethod · 0.65
errorMethod · 0.65

Tested by

no test coverage detected