run_ai_action
Execute AI-generated responses for specific messages using predefined prompts within the Carbon Voice platform. Supports multiple messages and customizable language settings for improved communication.
Instructions
Run an AI Action (Prompt) for a message. You can run an AI Action for a message by its ID or a list of message IDs.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| channel_id | No | ||
| language | No | The language of the response. Defaults to original message. | |
| message_ids | Yes | ||
| prompt_id | Yes | ||
| workspace_id | No |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"channel_id": {
"type": "string"
},
"language": {
"description": "The language of the response. Defaults to original message.",
"type": "string"
},
"message_ids": {
"items": {
"type": "string"
},
"type": "array"
},
"prompt_id": {
"type": "string"
},
"workspace_id": {
"type": "string"
}
},
"required": [
"prompt_id",
"message_ids"
],
"type": "object"
}
Implementation Reference
- src/server.ts:861-885 (registration)Registration of the MCP tool 'run_ai_action', including description, input schema reference, annotations, and wrapper handler function that calls the simplified API.server.registerTool( 'run_ai_action', { description: 'Run an AI Action (Prompt) for a message. You can run an AI Action for a message by its ID or a list of message IDs.', inputSchema: aIResponseControllerCreateResponseBody.shape, annotations: { readOnlyHint: false, destructiveHint: false, }, }, async (args: CreateAIResponse, { authInfo }): Promise<McpToolResponse> => { try { return formatToMCPToolResponse( await simplifiedApi.aIResponseControllerCreateResponse( args, setCarbonVoiceAuthHeader(authInfo?.token), ), ); } catch (error) { logger.error('Error running ai action:', { error }); return formatToMCPToolResponse(error); } }, );
- Core implementation of the AI response creation: makes a POST request to `/responses` endpoint with the CreateAIResponse body.const aIResponseControllerCreateResponse = ( createAIResponse: CreateAIResponse, options?: SecondParameter<typeof mutator>, ) => { return mutator<AIResponse>( { url: `/responses`, method: 'POST', headers: { 'Content-Type': 'application/json' }, data: createAIResponse, }, options, ); };
- Zod schema definition for the input body of aIResponseControllerCreateResponse, used as inputSchema.shape in tool registration.export const aIResponseControllerCreateResponseBody = zod.object({ "prompt_id": zod.string(), "message_ids": zod.array(zod.string()), "channel_id": zod.string().optional(), "workspace_id": zod.string().optional(), "language": zod.string().optional().describe('The language of the response. Defaults to original message.') })
- Factory function that creates the simplifiedApi object containing the aIResponseControllerCreateResponse method (excerpt abbreviated).export const getCarbonVoiceSimplifiedAPI = () => { const aIPromptControllerGetPrompts = ( params?: AIPromptControllerGetPromptsParams, options?: SecondParameter<typeof mutator>, ) => { return mutator<AIPrompt[]>( { url: `/prompts`, method: 'GET', params }, options, ); }; const aIPromptControllerCreatePrompt = ( createAIPrompt: CreateAIPrompt, options?: SecondParameter<typeof mutator>, ) => { return mutator<AIPrompt>( { url: `/prompts`, method: 'POST', headers: { 'Content-Type': 'application/json' }, data: createAIPrompt, }, options, ); }; const aIPromptControllerDeletePrompt = ( id: string, options?: SecondParameter<typeof mutator>, ) => { return mutator<boolean>( { url: `/prompts/${id}`, method: 'DELETE' }, options, ); }; const aIResponseControllerGetAllResponses = ( params?: AIResponseControllerGetAllResponsesParams, options?: SecondParameter<typeof mutator>, ) => { return mutator<AIResponse[]>( { url: `/responses`, method: 'GET', params }, options, ); }; const aIResponseControllerCreateResponse = ( createAIResponse: CreateAIResponse, options?: SecondParameter<typeof mutator>, ) => { return mutator<AIResponse>( { url: `/responses`, method: 'POST', headers: { 'Content-Type': 'application/json' }, data: createAIResponse, }, options, ); }; const aIResponseControllerGetLatestTenAIResponseByPrompt = ( promptId: string, options?: SecondParameter<typeof mutator>, ) => { return mutator<GetTenRecentAIPromptResponse>( { url: `/responses/prompt/${promptId}/latest-ten`, method: 'GET' }, options, ); }; /** * @summary Generate AI Prompt Response by share-link-ids */ const createShareLinkAIResponse = ( createShareLinkAIResponse: CreateShareLinkAIResponse, options?: SecondParameter<typeof mutator>, ) => { return mutator<AIShareLinkResponse>( { url: `/responses/share-link`, method: 'POST', headers: { 'Content-Type': 'application/json' }, data: createShareLinkAIResponse, }, options, ); }; const aIResponseControllerDeletePrompt = ( id: string, options?: SecondParameter<typeof mutator>, ) => { return mutator<boolean>( { url: `/responses/${id}`, method: 'DELETE' }, options, ); }; /** * Apps that the user has access to (subscribed or not). If the user is the owner of the app, details will be returned with the private fields. * @summary Get List of My Apps */ const getMyApps = (options?: SecondParameter<typeof mutator>) => { return mutator<App[]>({ url: `/apps`, method: 'GET' }, options); }; /** * @summary Subscribe user into app */ const subscribeUserIntoApp = ( clientId: string, subscribeUserPayload: SubscribeUserPayload, options?: SecondParameter<typeof mutator>, ) => { return mutator<SubscribedUser>( { url: `/apps/${clientId}/subscribe`, method: 'POST', headers: { 'Content-Type': 'application/json' }, data: subscribeUserPayload, }, options, ); }; /** * @summary Unsubscribe user from app */ const unsubscribeUserFromApp = ( clientId: string, options?: SecondParameter<typeof mutator>, ) => { return mutator<void>( { url: `/apps/${clientId}/unsubscribe`, method: 'DELETE' }, options, ); }; const languageControllerGetAll = ( options?: SecondParameter<typeof mutator>, ) => { return mutator<Language[]>( { url: `/languages/all`, method: 'GET' }, options, ); }; /** * @summary Get last ten recent Messages including (Conversation, Creator, Labels) */ const getTenRecentMessagesResponse = ( params?: GetTenRecentMessagesResponseParams, options?: SecondParameter<typeof mutator>, ) => { return mutator<GetTenRecentMessagesResponse>( { url: `/simplified/messages/latest-ten`, method: 'GET', params }, options, ); }; /** * @summary Get Message By ID */ const getMessageById = ( id: string, params?: GetMessageByIdParams, options?: SecondParameter<typeof mutator>, ) => { return mutator<GetMessageResponse>( { url: `/simplified/messages/${id}`, method: 'GET', params }, options, ); }; /** * By default return most recent messages. The **maximum** allowed range between dates is **183 days (6 months)**. * @summary List Messages */ const listMessages = ( params?: ListMessagesParams, options?: SecondParameter<typeof mutator>, ) => { return mutator<ListMessagesResponse>( { url: `/simplified/messages`, method: 'GET', params }, options, ); }; /** * Max number of links is **100** per API call. If you want to add more, should make another api call. * @summary Add Link Attachments to a message */ const addLinkAttachmentsToMessage = ( id: string, addLinkAttachmentPayload: AddLinkAttachmentPayload, options?: SecondParameter<typeof mutator>, ) => { return mutator<AddAttachmentsResponse>( { url: `/simplified/messages/${id}/attachments/bulk/link`, method: 'POST', headers: { 'Content-Type': 'application/json' }, data: addLinkAttachmentPayload, }, options, ); }; /** * In order to create a Message, you must provide **transcript** or **link** attachments. * @summary Send a Message to a Conversation */ const createConversationMessage = ( id: string, createConversationMessage: CreateConversationMessage, options?: SecondParameter<typeof mutator>, ) => { return mutator<GetMessageResponse>( { url: `/simplified/messages/conversation/${id}`, method: 'POST', headers: { 'Content-Type': 'application/json' }, data: createConversationMessage, }, options, ); }; /** * In order to create a Message, you must provide **transcript** or **link** attachments. * @summary Send a Direct Message to a User or a Group of Users */ const sendDirectMessage = ( sendDirectMessage: SendDirectMessage, options?: SecondParameter<typeof mutator>, ) => { return mutator<GetMessageResponse>( { url: `/simplified/messages/direct`, method: 'POST', headers: { 'Content-Type': 'application/json' }, data: sendDirectMessage, }, options, ); }; /** * In order to create a voicememo message, you must provide **transcript** or **link** attachments. * @summary Create a Voicememo Message */ const createVoiceMemoMessage = ( createVoicememoMessage: CreateVoicememoMessage, options?: SecondParameter<typeof mutator>, ) => { return mutator<GetMessageResponse>( { url: `/simplified/messages/voicememo`, method: 'POST', headers: { 'Content-Type': 'application/json' }, data: createVoicememoMessage, }, options, ); }; /** * It's required to inform one of (**email**, **phone**, **name**). When the search is by name, only user that are part of your contacts will be returned * @summary Search user by email, phone or name */ const searchUser = ( params?: SearchUserParams, options?: SecondParameter<typeof mutator>, ) => { return mutator<User>( { url: `/simplified/users/search`, method: 'GET', params }, options, ); }; /** * @summary Search users by their emails, phones or IDs */ const searchUsers = ( searchUsersBody: SearchUsersBody, options?: SecondParameter<typeof mutator>, ) => { return mutator<User[]>( { url: `/simplified/users/search`, method: 'POST', headers: { 'Content-Type': 'application/json' }, data: searchUsersBody, }, options, ); }; /** * @summary Get User By ID */ const getUserById = ( id: string, options?: SecondParameter<typeof mutator>, ) => { return mutator<User>( { url: `/simplified/users/${id}`, method: 'GET' }, options, ); }; /** * @summary Get all user conversations (Only _id and name available */ const getAllConversations = (options?: SecondParameter<typeof mutator>) => { return mutator<AllConversationsResponse>( { url: `/simplified/conversations/all`, method: 'GET' }, options, ); }; /** * @summary Get a conversation by id */ const getConversationById = ( id: string, options?: SecondParameter<typeof mutator>, ) => { return mutator<Conversation>( { url: `/simplified/conversations/${id}`, method: 'GET' }, options, ); }; /** * @summary Get Conversation Users */ const getConversationUsers = ( id: string, options?: SecondParameter<typeof mutator>, ) => { return mutator<User[]>( { url: `/simplified/conversations/${id}/users`, method: 'GET' }, options, ); }; /** * @summary Get all Workspaces that user has access to with basic info */ const getAllWorkspacesWithBasicInfo = ( options?: SecondParameter<typeof mutator>, ) => { return mutator<WorkspaceBasicInfo[]>( { url: `/simplified/workspaces/basic-info`, method: 'GET' }, options, ); }; /** * @summary List of System AI Prompts */ const getSystemAIPrompts = (options?: SecondParameter<typeof mutator>) => { return mutator<SimplifiedAIPrompt[]>( { url: `/simplified/public/system-prompts`, method: 'GET' }, options, ); }; /** * @summary Get Sample AI Responses for a System AI Prompt */ const getAiSystemPromptResponse = ( promptId: string, options?: SecondParameter<typeof mutator>, ) => { return mutator<AIPromptWithMessagesResponse>( { url: `/simplified/public/responses/prompt/${promptId}/sample`, method: 'GET', }, options, ); }; /** * @summary Get all root Folders */ const getAllRootFolders = ( params: GetAllRootFoldersParams, options?: SecondParameter<typeof mutator>, ) => { return mutator<ListFoldersResponse>( { url: `/simplified/folders`, method: 'GET', params }, options, ); }; /** * @summary Create a new Folder */ const createFolder = ( createFolderPayload: CreateFolderPayload, options?: SecondParameter<typeof mutator>, ) => { return mutator<Folder>( { url: `/simplified/folders`, method: 'POST', headers: { 'Content-Type': 'application/json' }, data: createFolderPayload, }, options, ); }; /** * @summary Get count of all folders, messages and message_ids not in folders grouped by workspace */ const getCountsGroupedByWorkspace = ( params: GetCountsGroupedByWorkspaceParams, options?: SecondParameter<typeof mutator>, ) => { return mutator<ListCountFoldersGroupedByWorkspace[]>( { url: `/simplified/folders/count-by-workspace`, method: 'GET', params }, options, ); }; /** * @summary Get Folder with Messages */ const getFolderMessages = ( id: string, options?: SecondParameter<typeof mutator>, ) => { return mutator<FolderWithMessages>( { url: `/simplified/folders/${id}/messages`, method: 'GET' }, options, ); }; /** * @summary Get Folder by ID */ const getFolderById = ( id: string, params?: GetFolderByIdParams, options?: SecondParameter<typeof mutator>, ) => { return mutator<Folder>( { url: `/simplified/folders/${id}`, method: 'GET', params }, options, ); }; /** * @summary Update Folder Name */ const updateFolderName = ( id: string, updateFolderNamePayload: UpdateFolderNamePayload, options?: SecondParameter<typeof mutator>, ) => { return mutator<Folder>( { url: `/simplified/folders/${id}`, method: 'PATCH', headers: { 'Content-Type': 'application/json' }, data: updateFolderNamePayload, }, options, ); }; /** * @summary Delete Folder and all subfolders and messages in nested folders */ const deleteFolder = ( id: string, options?: SecondParameter<typeof mutator>, ) => { return mutator<void>( { url: `/simplified/folders/${id}`, method: 'DELETE' }, options, ); }; /** * Only allowed to move messages of type: voicememo,prerecorded. * @summary Move a message into specific Folder or into a Workspace */ const addMessageToFolderOrWorkspace = ( addMessageToFolderPayload: AddMessageToFolderPayload, options?: SecondParameter<typeof mutator>, ) => { return mutator<MessageV2>( { url: `/simplified/folders/message`, method: 'PATCH', headers: { 'Content-Type': 'application/json' }, data: addMessageToFolderPayload, }, options, ); }; /** * @summary Move a Folder into another Folder or into a Workspace */ const moveFolder = ( id: string, moveFolderPayload: MoveFolderPayload, options?: SecondParameter<typeof mutator>, ) => { return mutator<Folder>( { url: `/simplified/folders/${id}/move`, method: 'PATCH', headers: { 'Content-Type': 'application/json' }, data: moveFolderPayload, }, options, ); }; return {