archiveContact
Permanently archive a contact in Mailmodo by providing their email address. The contact is removed from active lists and will not receive future communications.
Instructions
permanently archive contact in mailmodo
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| Yes |
Implementation Reference
- src/server.ts:307-337 (registration)Registration of the 'archiveContact' tool via server.tool() with an email string schema and handler that calls deleteContact.
server.tool( "archiveContact", "permanently archive contact in mailmodo", { email: z.string() }, async (params) => { try { const respone = await deleteContact(mmApiKey,params.email); // 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 deleted '${params.email} with message ${respone.message}`: `Something went wrong. Please check if the email is correct`, }] }; } catch (error) { return { content: [{ type: "text", text: error instanceof Error ? error.message : "Failed to delete", }], isError: true }; } } ); - src/server.ts:313-336 (handler)The async handler function for archiveContact: calls deleteContact(mmApiKey, email) and returns the response.
async (params) => { try { const respone = await deleteContact(mmApiKey,params.email); // 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 deleted '${params.email} with message ${respone.message}`: `Something went wrong. Please check if the email is correct`, }] }; } catch (error) { return { content: [{ type: "text", text: error instanceof Error ? error.message : "Failed to delete", }], isError: true }; } } - src/server.ts:310-312 (schema)Zod schema for archiveContact input: requires a string 'email' field.
{ email: z.string() }, - The deleteContact helper function that makes the actual API call to mailmodo to delete/archive a contact by email.
export async function deleteContact( mmApiKey: string, email: string ): Promise<AddContactToListResponse> { if (!email) { throw new Error('Email is a required field'); } try { const response = await axios.delete<AddContactToListResponse>( 'https://api.mailmodo.com/api/v1/contacts', { headers: { 'Accept': 'application/json', 'mmApiKey': mmApiKey || '' }, data: { email } } ); return response.data; } catch (error) { if (error instanceof AxiosError) { if(error.status === 400){ return { success: true, message: "User Doesn't exist in system or already archived" }; } return { success: false, message: error.response?.data?.message || 'Failed to delete contact' }; } throw new Error('An unexpected error occurred'); } - src/types/addContactsTypes.ts:77-81 (helper)The AddContactToListResponse interface used as the return type of deleteContact.
export interface AddContactToListResponse { // Define your expected response structure here success: boolean; message?: string; }