Skip to main content


A webhook is a type of event-driven architecture that allows one web application to communicate with another.

A webhook is essentially a user-defined HTTP callback that is triggered by an event, such as the creation of a new record in a database, a change in status of an issue on a bug tracker, or a new message on a chat application.

When the event occurs, the source system makes an HTTP request to the URL specified by the webhook, which triggers the webhook and the associated code to run. The payload of the HTTP request typically contains data related to the event, which the receiving system can use to take further action.

With Squid, you have the ability to expose webhooks and make them accessible to other internal and external services. To define a webhook, simply decorate a function within a class that extends the SquidService class with the @webhook decorator.


Backend code
import { SquidService, webhook } from '@squidcloud/backend';
import { WebhookRequest, WebhookResponse } from '@squidcloud/client';

export class ExampleService extends SquidService {
handleStripePayment(request: WebhookRequest): Promise<WebhookResponse | any> {
// TODO - add your business logic here
// You can use this.createWebhookResponse(...) to create a response.

To allow Squid to discover the webhook and the rest of the functions in the same service, make sure the service is exported in the service/index.ts file:

export * from './example-service';

The webhook URL takes the following format:


For example, the handleStripePayment webhook exposes the following URL:


When developing locally, you can access the webhook using this URL:


When deploying to the dev environment, you can access the webhook using this URL:


The request object provides the full HTTP context, such as the query parameters, body, headers, and more.

The following example code uses Squid's backend SDK to turn Squid AI for Your Website into an API, which replaces using the Squid Client SDK.

Backend code
import { secureAiChatbot, SquidService, webhook } from '@squidcloud/backend';
import { WebhookRequest } from '@squidcloud/client';

export class ExampleService extends SquidService {
@secureAiChatbot('INTEGRATION_ID', 'chat') // Name of the integration ID you created when you set up the AI Chatbot integration
allowChat(): boolean {
return true;

async askQuestion(request: WebhookRequest): Promise<string> {
if (!request.body?.question) throw new Error('MISSING_QUESTION');

const p: Promise<string> = new Promise((resolve, reject) => {
let res = '';
.chatbot('INTEGRATION_ID') // Name of the integration ID of your AI Chatbot integration
.profile('PROFILE_ID') // Name of the profile you created earlier in that same integration
next: (answer) => {
res = answer;
error: () => reject('INTERNAL_ERROR'),
complete: () => {
return await p;

To see the full SDK reference documentation for the webhook decorator, click here.