changeGroupInviteCode.tsā¢2.52 kB
import { z } from 'zod';
import { Tool } from '@modelcontextprotocol/sdk/types.js';
import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js';
import { makeApiRequest } from '../../utils/helpers.js';
export const changeGroupInviteCodeTool: Tool = {
name: 'change_group_invite_code',
description: 'Change the invite code for a WhatsApp group, generating a new invite link',
annotations: {
title: 'Change Group Invite Code',
readOnlyHint: false,
destructiveHint: true,
idempotentHint: false,
openWorldHint: true
},
inputSchema: {
type: 'object',
properties: {
id: {
type: 'string',
description: 'The ID of the group to change the invite code for'
},
customToken: {
type: 'string',
description: 'Override default token for this request'
},
customInstanceID: {
type: 'string',
description: 'Override default instance ID for this request'
}
},
required: ['id'],
additionalProperties: false
}
};
export async function handleChangeGroupInviteCode(args: any, context?: any) {
const schema = z.object({
id: z.string().min(1, 'Group ID cannot be empty'),
customToken: z.string().optional(),
customInstanceID: z.string().optional()
});
const { id, customToken, customInstanceID } = schema.parse(args);
const { log } = context || {};
try {
if (log) {
log.info("Changing group invite code", { groupId: id });
}
const response = await makeApiRequest('/api/changeGroupInviteCode', {
id
}, customToken, customInstanceID);
const newLink = response.newLink || response.inviteLink || response.link || 'No new link found';
if (log) {
log.info("Group invite code changed successfully", { groupId: id, hasNewLink: !!response.newLink });
}
return {
content: [{
type: 'text',
text: `ā
Group invite code changed successfully!\n\nš„ Group ID: ${id}\nš New Invite Link: ${newLink}\n\nā ļø Important: The old invite link is now invalid!\nš” Share the new link to invite people to the group.\nš This action invalidates all previous invite links.\n\nš Response: ${JSON.stringify(response, null, 2)}`
}]
};
} catch (error: any) {
if (log) {
log.error("Failed to change group invite code", { error: error.message, groupId: id });
}
throw new McpError(ErrorCode.InternalError, `Failed to change invite code for group ${id}: ${error.message}`);
}
}