Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

1.1 KB
Raw Blame
import { createAction } from '@activepieces/pieces-framework';
import { timelinesAiAuth, timelinesAiCommon } from '../common';
import { chatDropdown } from '../common/properties';

export const closeChat = createAction({
  auth: timelinesAiAuth,
  name: 'closeChat',
  classification: 'WRITE',
  displayName: 'Close Chat',
  description: 'Programmatically mark a chat as closed by its chat_id.',
  audience: 'both',
  aiMetadata: { description: 'Marks a TimelinesAI WhatsApp chat as closed, identified by its numeric chat_id. Use to resolve or archive a conversation once handling is done. Idempotent: closing an already-closed chat sets the same end state with no additional effect.', idempotent: true },
  props: {
    chat_id: chatDropdown({ required: true }),
  },
  async run({ auth: apiKey, propsValue: { chat_id } }) {
    const response = await timelinesAiCommon.updateChat({
      apiKey: apiKey,
      chat_id: Number(chat_id),
      closed: true,
    });
    if (response.status !== 'ok') {
      throw new Error(
        `Failed to close chat: ${response.message || 'Unknown error'}`
      );
    }
    return response;
  },
});