MCPcopy Index your code
hub / github.com/triggerdotdev/trigger.dev / #sendEvent

Method #sendEvent

apps/webapp/app/services/loops.server.ts:25–72  ·  view source on GitHub ↗
({
    email,
    userId,
    firstName,
    eventName,
    eventProperties,
  }: {
    email: string;
    userId: string;
    firstName?: string;
    eventName: string;
    eventProperties?: Record<string, string | number | boolean>;
  })

Source from the content-addressed store, hash-verified

23 }
24
25 async #sendEvent({
26 email,
27 userId,
28 firstName,
29 eventName,
30 eventProperties,
31 }: {
32 email: string;
33 userId: string;
34 firstName?: string;
35 eventName: string;
36 eventProperties?: Record<string, string | number | boolean>;
37 }) {
38 const options = {
39 method: "POST",
40 headers: { Authorization: `Bearer ${this.apiKey}`, "Content-Type": "application/json" },
41 body: JSON.stringify({
42 email,
43 userId,
44 firstName,
45 eventName,
46 eventProperties,
47 }),
48 };
49
50 try {
51 const response = await fetch("https://app.loops.so/api/v1/events/send", options);
52
53 if (!response.ok) {
54 logger.error(`Loops sendEvent ${eventName} bad status`, { status: response.status });
55 return false;
56 }
57
58 const responseBody = (await response.json()) as any;
59
60 if (!responseBody.success) {
61 logger.error(`Loops sendEvent ${eventName} failed response`, {
62 message: responseBody.message,
63 });
64 return false;
65 }
66
67 return true;
68 } catch (error) {
69 logger.error(`Loops sendEvent ${eventName} failed`, { error });
70 return false;
71 }
72 }
73}
74
75export const loopsClient = env.LOOPS_API_KEY ? new LoopsClient(env.LOOPS_API_KEY) : null;

Callers 1

userCreatedMethod · 0.95

Calls 3

jsonMethod · 0.80
errorMethod · 0.65
fetchFunction · 0.50

Tested by

no test coverage detected