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
TypeScript ai-agentai-agent-toolsai-agentsai-agents-frameworkmcpmcp-servermcp-toolsmcpsn8n-alternativeno-code-automationworkflowworkflow-automationworkflows
import { createTrigger, TriggerStrategy } from '@activepieces/pieces-framework';
import { makeRequest } from '../common/client';
import { oncehubAuth } from '../common/auth';
import { HttpMethod } from '@activepieces/pieces-common';
export const conversationStarted = createTrigger({
auth: oncehubAuth,
name: 'conversationStarted',
classification: 'READ',
displayName: 'Conversation Started',
description:
'Triggered when website visitor starts interacting with a chatbot.',
aiMetadata: {
description:
'Fires when a website visitor begins interacting with a OnceHub chatbot, starting a new conversation. The event carries the conversation with its contact and owner details.',
},
props: {},
sampleData: {
id: 'EVNT-KN56U3YL7C',
object: 'event',
creation_time: '2020-03-22T09:49:12Z',
type: 'conversation.started',
api_version: 'v2',
data: {
id: 'CVR-022EAEA41C',
object: 'conversation',
creation_time: '2021-07-13T12:28:24Z',
initiated_by: 'contact',
last_updated_time: '2021-07-13T12:33:54Z',
last_interacted_time: '2021-07-13T12:33:54Z',
contact: {
object: 'contact',
id: 'CTC-J4FR05BKEW',
creation_time: '2020-03-22T09:48:48Z',
last_updated_time: '2020-03-22T09:48:48Z',
last_interacted_time: null,
owner: 'USR-FSD423423',
status: 'Qualified',
city: 'New York',
company_size: '50-100',
company: 'Acme Inc',
country: 'United States',
email: '[email protected]',
employees: 1,
first_name: 'Carrie',
has_consent: false,
job_title: 'Executive Assistant',
last_name: 'Customer',
mobile_phone: '+12025550195',
phone: '+12025550100',
post_code: '10001',
salutation: 'Ms.',
state: 'New York',
street_address: '123 Main Street',
terms_of_sevice: false,
timezone: 'America/New_York',
custom_fields: [],
},
owner: {
first_name: 'Andrea',
last_name: 'Hartie',
email: '[email protected]',
role_name: 'Member',
timezone: 'America/Chicago',
teams: ['TM-GCJU8DLBTPY1'],
},
status: 'closed',
bot: 'BOT-62774A40FB',
'...': '[Additional Properties Truncated]',
},
},
type: TriggerStrategy.WEBHOOK,
async onEnable(context) {
const api_key = context.auth.secret_text;
const { webhookUrl } = context;
const response = await makeRequest(api_key, HttpMethod.POST, '/webhooks', {
url: webhookUrl,
name: `conversation started Webhook - ${new Date().getTime()}`,
events: ['conversation.started'],
});
await context.store.put('webhookId_conversationStarted', response.id);
},
async onDisable(context) {
const api_key = context.auth.secret_text;
const webhookId = await context.store.get<string>(
'webhookId_conversationStarted'
);
if (webhookId) {
await makeRequest(api_key, HttpMethod.DELETE, `/webhooks/${webhookId}`);
}
await context.store.delete('webhookId_conversationStarted');
},
async run(context) {
return [context.payload.body];
},
});