Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/services/sendgrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,4 +316,34 @@ export class SendGridService {
});
return response.body;
}

// Global Unsubscribe
async isInGlobalUnsubscribe(email: string) {
const [response] = await this.client.request({
method: 'GET',
url: `/v3/asm/suppressions/global/${email}`
});
return response.body.hasOwnProperty('recipient_email');
}

// Add to Global Unsubscribe
async addToGlobalUnsubscribe(email: string) {
const [response] = await this.client.request({
method: 'POST',
url: `/v3/asm/suppressions/global`,
body: {
recipient_emails: [email]
}
});
return response.body;
}

// Delete from Global Unsubscribe
async deleteFromGlobalUnsubscribe(email: string) {
const [response] = await this.client.request({
method: 'DELETE',
url: `/v3/asm/suppressions/global/${email}`
});
return response.body;
}
}
54 changes: 54 additions & 0 deletions src/tools/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,11 +370,65 @@ export const getToolDefinitions = (service: SendGridService) => [
},
required: ['list_id', 'emails']
}
},
{
name: 'is_in_global_unsubscribe',
description: 'Check if an email address is in the global unsubscribe list',
inputSchema: {
type: 'object',
properties: {
email: {
type: 'string',
description: 'Email address to check'
}
},
required: ['email']
}
},
{
name: 'add_to_global_unsubscribe',
description: 'Add an email address to the global unsubscribe list',
inputSchema: {
type: 'object',
properties: {
email: {
type: 'string',
description: 'Email address to add to the global unsubscribe list'
}
},
required: ['email']
}
},
{
name: 'delete_from_global_unsubscribe',
description: 'Delete an email address from the global unsubscribe list',
inputSchema: {
type: 'object',
properties: {
email: {
type: 'string',
description: 'Email address to delete from the global unsubscribe list'
}
},
required: ['email']
}
}
];

export const handleToolCall = async (service: SendGridService, name: string, args: any) => {
switch (name) {
case 'is_in_global_unsubscribe':
const isInGlobalUnsubscribe = await service.isInGlobalUnsubscribe(args.email);
return { content: [{ type: 'text', text: JSON.stringify(isInGlobalUnsubscribe, null, 2) }] };

case 'add_to_global_unsubscribe':
await service.addToGlobalUnsubscribe(args.email);
return { content: [{ type: 'text', text: `Email address ${args.email} added to the global unsubscribe list` }] };

case 'delete_from_global_unsubscribe':
await service.deleteFromGlobalUnsubscribe(args.email);
return { content: [{ type: 'text', text: `Email address ${args.email} deleted from the global unsubscribe list` }] };

case 'delete_contacts':
await service.deleteContactsByEmails(args.emails);
return { content: [{ type: 'text', text: `Successfully deleted ${args.emails.length} contacts` }] };
Expand Down