import Itzam from "itzam";const itzam = new Itzam(process.env.ITZAM_API_KEY);// Send the text generated to the URL providedexport const sendMessageToWebhook = async (message: string) => { return await itzam.generateText({ input: "What is the capital of France?", workflowSlug: "french-chatbot", type: "event", callback: { url: "https://yoursite.com/webhook", headers: { Authorization: "your_secret_key", }, }, });};
For this example, let’s imagine you want to send AI responses to your website. This is how you can do it:
Copy
export const sendMessageToWebhook = async (question: string) => { const response = await itzam.generateText({ input: question, workflowSlug: "french-expert", type: "event", // Use this type to indicate that you are using webhooks callback: { url: "https://yoursite.com/webhook", // The URL to send the response to // You can add headers to the request headers: { Authorization: "your_secret_key", }, // You can also add a custom properties object to the response customProperties: { user_id: "user_123", }, }, }); return response;};
The webhook body will look like this:
Copy
{ "object": { "response": "The least populated city in France is Rochefourchat." }, "metadata": { "cost": "0.0000114", "model": { "name": "Gemini 2.0 Flash", "tag": "google:gemini-2.0-flash" }, "durationInMs": 742, "inputTokens": 38, "outputTokens": 19, "runId": "01981e5d-d5ea-768c-98e1-462fb1d43d92" }, "customProperties": { "user_id": "user_123" }}