100 lines
3.1 KiB
TypeScript
100 lines
3.1 KiB
TypeScript
/**
|
|
* ActiveCampaign Campaign Tools
|
|
*/
|
|
|
|
import { ActiveCampaignClient } from '../client/index.js';
|
|
import { Campaign } from '../types/index.js';
|
|
|
|
export function createCampaignTools(client: ActiveCampaignClient) {
|
|
return {
|
|
ac_list_campaigns: {
|
|
description: 'List all campaigns',
|
|
inputSchema: {
|
|
type: 'object',
|
|
properties: {
|
|
type: { type: 'string', description: 'Campaign type filter' },
|
|
status: { type: 'number', description: 'Status filter' },
|
|
limit: { type: 'number', description: 'Max results', default: 20 },
|
|
},
|
|
},
|
|
handler: async (params: any) => {
|
|
const campaigns = await client.paginate<Campaign>('/campaigns', params, params.limit || 20);
|
|
return { campaigns, count: campaigns.length };
|
|
},
|
|
},
|
|
|
|
ac_get_campaign: {
|
|
description: 'Get a campaign by ID',
|
|
inputSchema: {
|
|
type: 'object',
|
|
properties: {
|
|
id: { type: 'string', description: 'Campaign ID' },
|
|
},
|
|
required: ['id'],
|
|
},
|
|
handler: async (params: { id: string }) => {
|
|
return client.get<{ campaign: Campaign }>(`/campaigns/${params.id}`);
|
|
},
|
|
},
|
|
|
|
ac_create_campaign: {
|
|
description: 'Create a new campaign',
|
|
inputSchema: {
|
|
type: 'object',
|
|
properties: {
|
|
type: {
|
|
type: 'string',
|
|
description: 'Campaign type',
|
|
enum: ['single', 'recurring', 'split', 'responder', 'reminder', 'special', 'activerss', 'automation'],
|
|
},
|
|
name: { type: 'string', description: 'Campaign name' },
|
|
userid: { type: 'string', description: 'User ID' },
|
|
},
|
|
required: ['type', 'name'],
|
|
},
|
|
handler: async (params: Campaign) => {
|
|
return client.post<{ campaign: Campaign }>('/campaigns', { campaign: params });
|
|
},
|
|
},
|
|
|
|
ac_get_campaign_stats: {
|
|
description: 'Get campaign statistics',
|
|
inputSchema: {
|
|
type: 'object',
|
|
properties: {
|
|
id: { type: 'string', description: 'Campaign ID' },
|
|
},
|
|
required: ['id'],
|
|
},
|
|
handler: async (params: { id: string }) => {
|
|
const campaign = await client.get<{ campaign: Campaign }>(`/campaigns/${params.id}`);
|
|
return {
|
|
campaign: (campaign as any).campaign,
|
|
stats: {
|
|
opens: (campaign as any).campaign.opens,
|
|
uniqueOpens: (campaign as any).campaign.uniqueopens,
|
|
clicks: (campaign as any).campaign.linkclicks,
|
|
uniqueClicks: (campaign as any).campaign.uniquelinkclicks,
|
|
unsubscribes: (campaign as any).campaign.unsubscribes,
|
|
bounces: (campaign as any).campaign.hardbounces,
|
|
},
|
|
};
|
|
},
|
|
},
|
|
|
|
ac_delete_campaign: {
|
|
description: 'Delete a campaign',
|
|
inputSchema: {
|
|
type: 'object',
|
|
properties: {
|
|
id: { type: 'string', description: 'Campaign ID' },
|
|
},
|
|
required: ['id'],
|
|
},
|
|
handler: async (params: { id: string }) => {
|
|
return client.delete(`/campaigns/${params.id}`);
|
|
},
|
|
},
|
|
};
|
|
}
|