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.9 KB
Raw Blame
import { createAction, Property } from '@activepieces/pieces-framework';
import { connectucAuth } from '../../index';
import { connectucApiCall } from '../common/api-helpers';
import { domainProp, subscriberUuidProp } from '../common/props';
import { HttpMethod } from '@activepieces/pieces-common';

export const doNotDisturbAction = createAction({
    auth: connectucAuth,
    name: 'do-not-disturb',
    classification: 'WRITE',
    displayName: 'Set Do Not Disturb',
    description: 'Enable or disable Do Not Disturb status for a user in ConnectUC',
    audience: 'both',
    aiMetadata: { description: 'Sets a ConnectUC user\'s Do Not Disturb (DND) state to on or off via the DND checkbox, for the given domain and subscriber. Use when an agent needs to silence or re-enable a user\'s incoming calls. Idempotent: it sets DND to an absolute on/off value, so repeating the same call leaves the user in the same final state.', idempotent: true },
    props: {
        domain: domainProp(),
        user: subscriberUuidProp(),
        dnd: Property.Checkbox({
            displayName: 'Do Not Disturb',
            description: 'Enable or disable Do Not Disturb status',
            required: true,
        }),
    },
    async run(context) {
        const { user, dnd } = context.propsValue;

        const body: Record<string, unknown> = {
            dnd: dnd,
        };

        try {
            const response = await connectucApiCall({
                accessToken: context.auth.access_token,
                endpoint: `/users/${user}/dnd/update`,
                method: HttpMethod.POST,
                body,
            });

            return response;
        } catch (error: unknown) {
            const message = error instanceof Error ? error.message : 'Unknown error occurred';
            throw new Error(`Failed to set Do Not Disturb status: ${message}`);
        }
    },
});