Skip to content

Commit

Permalink
feat(tools): add Zapier Webhook tool (#173)
Browse files Browse the repository at this point in the history
# Zapier Webhook Tool

The Zapier Webhook Tool allows AI agents to interact with Zapier's
webhook service, enabling seamless integration with thousands of apps
and services supported by Zapier.

## Purpose

The Zapier Webhook Tool is designed to extend the capabilities of AI
agents by allowing them to trigger workflows and automate tasks across
various applications using Zapier's webhook functionality. This tool is
ideal for scenarios where agents need to interact with multiple services
and automate complex workflows.

## Features

- Easy integration with Zapier's webhook service
- Trigger workflows and automate tasks across thousands of apps
- Configurable options for webhook events and payloads

## Usage

To use the Zapier Webhook Tool, follow these steps:

**Configure the Tool**: Create an instance of the `ZapierWebhook` tool
with the required configuration.

```javascript
import { z } from 'zod';

const zapierTool = new ZapierWebhook({
  url: 'https://hooks.zapier.com/hooks/catch/4716958/2sdvyu2', // Set your Zapier webhook URL here
  schema: z.object({
    emailSubject: z.string().describe('The subject of the email.'),
    issuesSummary: z.string().describe('The summary of the issues.'),
  }),
});
```

**Use the Tool**: Integrate the tool into your workflow or agent.

```javascript
const response = await zapierTool._call({
  emailSubject: 'Weekly GitHub Issues Report',
  issuesSummary: 'Summary of the issues found in the repository.',
});

console.log(response);
```

For questions or discussions, join our
[Discord](https://kaibanjs.com/discord).

## License

MIT License
  • Loading branch information
darielnoel authored Dec 19, 2024
2 parents 9776374 + f065f25 commit 161fedd
Show file tree
Hide file tree
Showing 11 changed files with 958 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@
"./textfile-search": {
"import": "./dist/textfile-search/index.esm.js",
"require": "./dist/textfile-search/index.cjs.js"
},
"./zapier-webhook": {
"import": "./dist/zapier-webhook/index.esm.js",
"require": "./dist/zapier-webhook/index.cjs.js"
},
"./make-webhook": {
"import": "./dist/make-webhook/index.esm.js",
"require": "./dist/make-webhook/index.cjs.js"
}
},
"files": [
Expand Down
2 changes: 2 additions & 0 deletions packages/tools/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const toolFolders = [
'website-search',
'pdf-search',
'textfile-search',
'zapier-webhook',
'make-webhook',
]; // Add more folder names as needed

const toolConfigs = toolFolders.map((tool) => {
Expand Down
2 changes: 2 additions & 0 deletions packages/tools/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ export * from './simple-rag/index.js';
export * from './website-search/index.js';
export * from './pdf-search/index.js';
export * from './textfile-search/index.js';
export * from './zapier-webhook/index.js';
export * from './make-webhook/index.js';
48 changes: 48 additions & 0 deletions packages/tools/src/make-webhook/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Make Webhook Tool

The Make Webhook Tool allows AI agents to interact with Make's webhook service, enabling seamless integration with thousands of apps and services supported by Make.

## Purpose

The Make Webhook Tool is designed to extend the capabilities of AI agents by allowing them to trigger workflows and automate tasks across various applications using Make's webhook functionality. This tool is ideal for scenarios where agents need to interact with multiple services and automate complex workflows.

## Features

- Easy integration with Make's webhook service
- Trigger workflows and automate tasks across thousands of apps
- Configurable options for webhook events and payloads

## Usage

To use the Make Webhook Tool, follow these steps:

**Configure the Tool**: Create an instance of the `MakeWebhook` tool with the required configuration.

```javascript
import { z } from 'zod';

const MakeTool = new MakeWebhook({
url: 'https://hooks.Make.com/hooks/catch/4716958/2sdvyu2', // Set your Make webhook URL here
schema: z.object({
emailSubject: z.string().describe('The subject of the email.'),
issuesSummary: z.string().describe('The summary of the issues.'),
}),
});
```

**Use the Tool**: Integrate the tool into your workflow or agent.

```javascript
const response = await MakeTool._call({
emailSubject: 'Weekly GitHub Issues Report',
issuesSummary: 'Summary of the issues found in the repository.',
});

console.log(response);
```

For questions or discussions, join our [Discord](https://kaibanjs.com/discord).

## License

MIT License
90 changes: 90 additions & 0 deletions packages/tools/src/make-webhook/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/**
* Make Webhook Tool
*
* This tool allows integration with Make's webhook service, enabling seamless
* interaction with thousands of apps and services supported by Make. It is
* designed to trigger workflows and automate tasks across various applications
* using Make's webhook functionality.
*
* Key features of Make Webhook Tool:
* - Easy integration with Make's webhook service
* - Trigger workflows and automate tasks across thousands of apps
* - Configurable options for webhook events and payloads
*
* Usage:
* const MakeTool = new MakeWebhook({
* url: 'https://hooks.Make.com/hooks/catch/4716958/2sdvyu2', // Set your Make webhook URL here
* schema: z.object({
* emailSubject: z.string().describe('The subject of the email.'),
* issuesSummary: z.string().describe('The summary of the issues.'),
* }),
* });
* const response = await MakeTool._call({
* emailSubject: 'Weekly GitHub Issues Report',
* issuesSummary: 'Summary of the issues found in the repository.',
* });
*
* For more information about Make, visit: https://Make.com/
*/

import { Tool } from '@langchain/core/tools';
import ky from 'ky';
import { HTTPError } from 'ky';

/**
* Class representing a Make Webhook tool.
* @extends Tool
*/
export class MakeWebhook extends Tool {
/**
* Create a MakeWebhook tool.
* @param {Object} fields - The configuration fields for the tool.
* @param {string} fields.url - The Make webhook URL.
* @param {Object} fields.schema - The schema for the input data using Zod.
*/
constructor(fields) {
super(fields);
this.url = fields.url;
this.name = 'make_webhook';
this.description =
'A tool for triggering Make webhooks to integrate with various services. Input should be a JSON object with the necessary data for the webhook.';

this.httpClient = ky;
this.schema = fields.schema;
}

/**
* Call the Make webhook with the provided input data.
* @param {Object} input - The input data for the webhook.
* @returns {Promise<string>} The response from the webhook as a JSON string.
*/
async _call(input) {
try {
const response = await this.httpClient.post(this.url, {
json: input,
headers: {
'Content-Type': 'application/json',
},
});

if (!response.ok) {
return 'Could not parse Make webhook response. Please try again.';
}

return 'Webhook response success';
} catch (error) {
if (error instanceof HTTPError) {
const statusCode = error.response.status;
let errorType = 'Unknown';
if (statusCode >= 400 && statusCode < 500) {
errorType = 'Client Error';
} else if (statusCode >= 500) {
errorType = 'Server Error';
}
return `API request failed: ${errorType} (${statusCode})`;
} else {
return `An unexpected error occurred: ${error.message}`;
}
}
}
}
93 changes: 93 additions & 0 deletions packages/tools/src/make-webhook/tool.stories.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { z } from 'zod';
import { ToolPreviewer } from '../_utils/ToolPreviewer.jsx';
import { AgentWithToolPreviewer } from '../_utils/AgentWithToolPreviewer.jsx';
import { GithubIssues } from '../github-issues/index.js';
import { MakeWebhook } from './index.js';
import { Agent, Task, Team } from '../../../../src/index';
import React from 'react';

export default {
title: 'Tools/Make Webhook',
parameters: {
layout: 'centered',
},
tags: ['autodocs'],
argTypes: {},
};

const githubTool = new GithubIssues({
token: import.meta.env.VITE_GITHUB_TOKEN,
limit: 5,
});

const makeTool = new MakeWebhook({
url: 'https://hook.us2.make.com/fwxq61cn8k5f6143rsomlk3plcupsypp', // Set your Make webhook URL here
schema: z.object({
emailSubject: z.string().describe('The subject of the email.'),
issuesSummary: z.string().describe('The summary of the issues.'),
}),
});

export const Default = {
render: (args) => <ToolPreviewer {...args} />,
args: {
toolInstance: makeTool,
callParams: {
emailSubject: 'Weekly GitHub Issues Report',
issuesSummary: 'Summary of the issues found in the repository.',
},
},
};

// Create an agent with the GitHub tool
const issueAnalyzer = new Agent({
name: 'Issue Analyzer',
role: 'GitHub Repository Inspector',
goal: 'Analyze and summarize GitHub repository issues',
tools: [githubTool],
});

// Create an agent with the Make webhook tool
const emailSender = new Agent({
name: 'Email Sender',
role: 'Email Reporter',
goal: 'Send summarized issues via email using Make webhook',
tools: [makeTool],
});

// Create an analysis task
const issueAnalysisTask = new Task({
description:
'Fetch and analyze issues from the following repository: {repoUrl}',
agent: issueAnalyzer,
expectedOutput: 'A structured summary of repository issues',
});

// Create a task to send the summary via Make webhook
const sendEmailTask = new Task({
description: 'Send the summarized issues via Make webhook',
agent: emailSender,
expectedOutput: 'A confirmation that the email was sent successfully',
});

// Create the team
const team = new Team({
name: 'Issue Reporting Team',
description:
'Team to fetch GitHub issues and send them via email using Make webhook',
agents: [issueAnalyzer, emailSender],
tasks: [issueAnalysisTask, sendEmailTask],
inputs: {
repoUrl: 'https://github.com/facebook/react',
},
env: {
OPENAI_API_KEY: import.meta.env.VITE_OPENAI_API_KEY,
},
});

export const withAgent = {
render: (args) => <AgentWithToolPreviewer {...args} />,
args: {
team: team,
},
};
Loading

0 comments on commit 161fedd

Please sign in to comment.