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.3 KB
Raw Blame
import { createAction, Property } from '@activepieces/pieces-framework';
import { httpClient, HttpMethod } from '@activepieces/pieces-common';
import { talkableAuth } from '../../..';
import { TALKABLE_API_URL } from '../../common/constants';

export const findCoupon = createAction({
  name: 'find_coupon', // Must be a unique across the piece, this shouldn't be changed.
  classification: 'READ',
  auth: talkableAuth,
  displayName: 'Find coupon',
  description: 'Find coupon code',
  audience: 'both',
  aiMetadata: { description: 'Look up a Talkable coupon by its code and return its details. Use to verify a coupon exists or inspect its status/value. Read-only; the coupon code is required.', idempotent: true },
  props: {
    code: Property.ShortText({
      displayName: 'Coupon code',
      description: undefined,
      required: true,
    }),
  },
  async run(context) {
    const { site, api_key } = context.auth.props;
    const couponInfoResponse = await httpClient
      .sendRequest<string[]>({
        method: HttpMethod.GET,
        url: `${TALKABLE_API_URL}/coupons/${context.propsValue['code']}`,
        headers: {
          Authorization: `Bearer ${api_key}`,
          'Content-Type': 'application/json',
        },
        queryParams: {
          site_slug: site,
        },
      });
    return couponInfoResponse.body;
  },
});