-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tools): add Zapier Webhook tool (#173)
# 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
Showing
11 changed files
with
958 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
}; |
Oops, something went wrong.