Function Creation and Webhook Setup Guide
Introduction
This guide explains how to create functions for your Peki chatbot and set up a webhook server to handle data processing. Functions allow your chatbot to collect specific information from users and send this data to your webhook server for processing.
Dashboard Access
The Peki Dashboard is accessible at:
https://dashboard.peki.ai/dashboard/{chatbotId}/chatbot/functions
Important: Replace {chatbotId}
with your actual chatbot ID from the Peki platform.
Process Overview
- First, we'll create a function using the Peki Dashboard
- Then, we'll set up a webhook server to process the data
- Finally, we'll test the integration
When a user interacts with your chatbot:
- The AI collects required information using defined properties
- The data is sent to your webhook server using the HTTP Action
- Your server processes the data and sends back a response
- The AI presents the results to the user using the response template
Function Configuration Fields
1. Basic Information
Field | Example Value | Description |
---|---|---|
Name | Credit Limit Check | Display name of the function |
Description | Important: Collects necessary parameters from user to check credit score and determine limit. | Detailed explanation of function's purpose |
2. Properties Configuration
Each property requires the following fields:
Field | Type | Required | Description |
---|---|---|---|
Name | String | Yes | Unique identifier for the property |
Description | String | Yes | Instructions for AI to collect the information |
IsRequired | Boolean | Yes | Whether this property must be collected |
Example Properties Table
Name | Description | IsRequired |
---|---|---|
bank | Name of the bank to check credit score | Yes |
loanAmount | Amount of loan to be taken | Yes |
3. HTTP Action Configuration
Field | Example Value | Description |
---|---|---|
Name | Http Action | Display name of the action |
Url | http://localhost:3001/webhook/credit | Endpoint URL for the webhook |
Method | POST | HTTP method (GET or POST) |
4. Response Configuration
Field | Example Value | Description |
---|---|---|
Response | Summarize the response from {bank} for loan amount {loanAmount} | Template for AI to format response |
Function Creation Process
1. Access Dashboard
- Navigate to the Peki Dashboard using your chatbot ID
- Click "Create New Function"
2. Configure Basic Settings
Field to Fill | What to Enter |
---|---|
Name | Your function name (e.g., "Credit Limit Check") |
Description | Clear explanation of function purpose |
3. Add Properties
Step | Action |
---|---|
1 | Click "Add Property" |
2 | Enter property name (e.g., "bank") |
3 | Write clear description |
4 | Set Required flag |
5 | Repeat for all properties |
4. Configure HTTP Action
Step | Action |
---|---|
1 | Enter webhook URL |
2 | Select HTTP method |
3 | Save action settings |
5. Set Response Template
Step | Action |
---|---|
1 | Write response template using {propertyName} syntax |
2 | Test template with sample values |
Webhook Setup
1. Basic Node.js Server Setup
const express = require("express");
const bodyParser = require("body-parser");
const app = express();
app.use(bodyParser.json());
2. Create Webhook Endpoint
app.post("/webhook/credit", async (req, res) => {
try {
const { arguments } = req.body;
// Extract user and function data
const {
chatUserId, // Unique chat user ID
platformId, // User ID from script
bank, // Collected by AI
loanAmount, // Collected by AI
} = arguments;
// Process credit check logic
const creditResult = await processCreditCheck({
userId: platformId,
bank,
loanAmount,
});
// Send response
res.json({
success: true,
data: creditResult,
});
} catch (error) {
console.error("Webhook error:", error);
res.status(500).json({
success: false,
message: error.message,
});
}
});
3. Start Server
const PORT = process.env.PORT || 3001;
app.listen(PORT, () => {
console.log(`Webhook server running on port ${PORT}`);
});
Function Execution Flow
Step | Description |
---|---|
1. AI Trigger | AI recognizes intent and starts property collection |
2. Data Collection | AI asks user for each required property |
3. Validation | System ensures all required properties are collected |
4. Webhook Call | System sends data to webhook URL |
5. Processing | Webhook processes request and returns result |
6. Response | AI formats response using template and presents to user |
Best Practices
1. Property Naming
Do | Don't |
---|---|
Use clear, descriptive names | Use generic names |
Use camelCase or snake_case | Use spaces or special characters |
Keep names concise | Use very long names |
2. Property Descriptions
Do | Don't |
---|---|
Write clear instructions | Use technical jargon |
Include format requirements | Be vague or unclear |
Specify any constraints | Assume AI understands context |
3. Webhook Implementation
Practice | Description |
---|---|
Security | Use HTTPS in production |
Validation | Check all incoming data |
Error Handling | Implement proper error handling |
Logging | Log all requests and responses |
Timeouts | Include timeout handling |
4. Testing
Test Case | What to Check |
---|---|
Happy Path | Basic successful flow |
Missing Data | Handling of missing properties |
Invalid Data | Error handling for invalid input |
Response Format | Correct template processing |
Troubleshooting
Issue | Solution |
---|---|
Webhook not receiving data | Check URL and network settings |
Missing properties | Verify property configuration |
Response not formatting | Check template syntax |
Server errors | Check logs and error handling |