Looking to build a custom approval bot using the latest OpenAI API capabilities? Whether you want to automate document sign-offs, expense approvals, or code reviews, OpenAI's June 2026 API updates offer powerful new features to streamline these workflows with AI. In this Builder’s Corner deep dive, you’ll learn how to create a robust, secure, and extensible approval bot—step by step, from setup to deployment.
For broader context on workflow automation, see our parent guide on automating workflow approval loops with custom AI agents.
Prerequisites
- OpenAI API Access: June 2026 release (v3.8+), with
function_callingandwebhooksupport enabled - Node.js v20+ or Python 3.11+
- ngrok (for local webhook testing)
- Basic knowledge of REST APIs, JSON, and your preferred programming language
- Git (for version control)
- Optional: Familiarity with AI workflow integration with chat platforms
-
Set Up Your Project Environment
Start by creating a new project directory and initializing your environment. For this tutorial, we’ll use Node.js, but Python users can adapt the steps similarly.
mkdir openai-approval-bot cd openai-approval-bot git init npm init -y npm install openai express dotenv
Tip: Use
python -m venv venvandpip install openai flask python-dotenvif you prefer Python.Create a
.envfile to store your OpenAI API key:OPENAI_API_KEY=sk-...
-
Define Approval Workflow Logic
Decide what triggers an approval, what data is required, and how approvals are granted or denied. For illustration, let’s build a bot that approves or rejects expense requests based on company policy.
- Input: Expense request (amount, description, requester)
- Rules: Approve if <$500 and valid description; escalate otherwise
- Output: Approval decision with rationale
Create a
approvalPolicy.jsfile:// approvalPolicy.js module.exports = function evaluateExpense(expense) { if (expense.amount < 500 && expense.description.length > 10) { return { decision: "approved", reason: "Amount under threshold and valid description." }; } return { decision: "escalate", reason: "Requires manual review." }; } -
Implement the OpenAI Function Calling Interface
The June 2026 API introduces enhanced
function_calling—allowing bots to invoke custom logic during conversations. Register your approval function and describe its parameters.In
bot.js:require('dotenv').config(); const { OpenAI } = require('openai'); const express = require('express'); const evaluateExpense = require('./approvalPolicy'); const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY }); const app = express(); app.use(express.json()); const approvalFunction = { name: "evaluateExpense", description: "Evaluate an expense request for approval.", parameters: { type: "object", properties: { amount: { type: "number", description: "Expense amount in USD" }, description: { type: "string", description: "Expense purpose" }, requester: { type: "string", description: "Employee name" } }, required: ["amount", "description", "requester"] } }; app.post('/api/approval', async (req, res) => { const userInput = req.body; // Step 1: Use OpenAI to parse and route the request const completion = await openai.chat.completions.create({ model: "gpt-4o-2026-06", messages: [ { role: "system", content: "You are an approval bot." }, { role: "user", content: JSON.stringify(userInput) } ], functions: [approvalFunction], function_call: "auto" }); if (completion.choices[0].finish_reason === "function_call") { // Step 2: Call custom logic const args = JSON.parse(completion.choices[0].message.function_call.arguments); const result = evaluateExpense(args); // Step 3: Respond to user res.json(result); } else { res.status(400).json({ error: "Could not process approval." }); } }); const PORT = process.env.PORT || 3000; app.listen(PORT, () => console.log(`Approval bot running on port ${PORT}`));Screenshot Description: Terminal output showing
Approval bot running on port 3000. -
Test Locally with ngrok and Sample Requests
To test webhooks or remote integrations, expose your local server:
npx ngrok http 3000
Send a sample approval request with
curl:curl -X POST https://<your-ngrok-url>/api/approval \ -H "Content-Type: application/json" \ -d '{"amount": 350, "description": "Team lunch for client meeting", "requester": "Alice"}'Expected Output:
{"decision":"approved","reason":"Amount under threshold and valid description."}Try a request that should escalate:
curl -X POST https://<your-ngrok-url>/api/approval \ -H "Content-Type: application/json" \ -d '{"amount": 1200, "description": "Laptop", "requester": "Bob"}'{"decision":"escalate","reason":"Requires manual review."} -
Enhance with OpenAI Webhooks for Real-Time Notifications
The June 2026 update allows bots to trigger webhooks for approvals or escalations. Let’s notify a Slack channel (or any webhook endpoint) when an approval is made.
Add a webhook call to your approval logic:
// Add inside the /api/approval route, after result is determined: const axios = require('axios'); if (result.decision === "approved") { await axios.post('https://hooks.slack.com/services/your/webhook/url', { text: `✅ Expense approved for ${args.requester}: $${args.amount} - ${args.description}` }); }Screenshot Description: Slack channel showing “✅ Expense approved for Alice: $350 - Team lunch for client meeting”.
For more on integrating bots with chat platforms, see Integrating AI Workflow Automation with Enterprise Chat Platforms: Top 2026 Approaches.
-
Secure and Deploy Your Approval Bot
Before deploying, secure your endpoints:
- Use API keys or OAuth for authentication
- Validate all input data
- Log all approval actions for audit
Deploy to your preferred cloud provider (e.g., Vercel, AWS, Azure, GCP). Example for Vercel:
npx vercel deploy
Screenshot Description: Vercel dashboard showing “openai-approval-bot” deployment status.
Common Issues & Troubleshooting
-
OpenAI API errors: Check your API key, usage limits, and ensure you’re on the June 2026 endpoint (
gpt-4o-2026-06or later). -
Webhook failures: Confirm your webhook URL is reachable (use
curlto test), and check for required headers. -
Function_call not triggered: Ensure your function schema matches the input, and that
function_call: "auto"is set in your OpenAI request. - Security issues: Always sanitize and validate user input. Never expose your OpenAI API key in client-side code.
- ngrok not forwarding: Restart ngrok, check your firewall, and ensure your local server is running.
Next Steps
- Expand workflow logic: Add multi-step approvals, document attachments, or custom escalation paths.
- Integrate with enterprise platforms: Connect your bot to Microsoft Teams, Slack, or Jira for seamless workflow automation.
- Explore prompt engineering: Optimize your AI prompts for better accuracy—see Prompt Engineering Tactics for Automated Marketing Campaigns in 2026.
- Automate data extraction: For document-based approvals, check out How to Build a Document Data Extraction Workflow with Open-Source AI (2026 Edition).
- Deepen your understanding: Revisit How to Automate Workflow Approval Loops with Custom AI Agents (Step-by-Step, 2026) for advanced strategies.
With these steps, you can confidently build, test, and deploy a custom approval bot using OpenAI’s latest API features. The June 2026 updates make it easier than ever to automate routine decisions—freeing your team for higher-value work.