sendEvent
Track and send custom email events with specific details like event name and properties using Mailmodo. Enhance user engagement and data collection.
Instructions
Send custom events with email, event name and event properties
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| Yes | |||
| event_name | Yes | ||
| event_properties | No | ||
| ts | No |
Implementation Reference
- src/server.ts:118-151 (registration)Registration of the 'sendEvent' tool including inline handler and input schema definition.server.tool( "sendEvent", "Send custom events with email, event name and event properties", { email: z.string(), event_name: z.string(), ts: z.number().optional(), event_properties: eventPropertiesSchema.optional(), }, async (params) => { try { const respone = await addMailmodoEvent(mmApiKey,params); // Here you would typically integrate with your event sending system // For example: eventBus.emit(eventName, eventData) // For demonstration, we'll just return a success message return { content: [{ type: "text", text: respone.success?`Successfully sent event '${params.event_name}' for email ${params.email} with payload: ${JSON.stringify(params.event_properties)} with reference id ${respone.ref}`: `Something went wrong. Please check if the email is correct`, }] }; } catch (error) { return { content: [{ type: "text", text: error instanceof Error ? error.message : "Failed to send event", }], isError: true }; } } );
- src/apicalls/sendEvents.ts:13-45 (handler)Core handler logic for sending the custom event to Mailmodo API via POST request.export async function addMailmodoEvent( mmApiKey: string, payload: MailmodoEvent ): Promise<AddCustomeEventResponse> { if (!payload.email || !payload.event_name) { throw new Error('Email and event_name are required fields'); } try { const response = await axios.post<AddCustomeEventResponse>( 'https://api.mailmodo.com/api/v1/addEvent', { ...payload, ts: payload.ts || Math.floor(Date.now() / 1000) }, { headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', 'mmApiKey': mmApiKey || '' } } ); return response.data; } catch (error) { if (error instanceof AxiosError) { return {success: false} } throw new Error('An unexpected error occurred'); } }
- Zod schema definition for event_properties object used in sendEvent tool input.export const eventPropertiesSchema = z.record( z.union([ z.string(), z.number(), z.boolean(), z.undefined() ]) );
- TypeScript interface defining the MailmodoEvent payload structure for sendEvent.export interface MailmodoEvent { email: string; event_name: string; ts?: number; event_properties?: EventProperties; }
- TypeScript interface for the API response from addEvent endpoint.export interface AddCustomeEventResponse { // Define your expected response structure here success: boolean; ref?: string; }