Skip to main content
Use this page as copy-paste context when asking an AI coding assistant to build against Visito’s M2M API.

Integration Context

You are integrating with the Visito M2M API.

Base URL: https://api.visitoai.com/m2m/v1
Authentication: Authorization: Bearer $VISITO_M2M_TOKEN
Token location: server-side environment variable only

Important rules:
- Never expose the M2M token in browser or mobile client code.
- Use only the scopes required for the integration.
- Send operations are asynchronous and return 202 Accepted with status "queued".
- Include Idempotency-Key on outbound send requests.
- Treat structured error codes as stable programmatic signals.

Endpoint Summary

Channels:
- GET /channels

Conversations:
- GET /conversations
- GET /conversations/{conversationId}
- POST /conversations/{conversationId}/reply

WhatsApp templates:
- GET /whatsapp-templates/{channelId}
- POST /whatsapp-templates/{channelId}
- POST /whatsapp-templates/{channelId}/send

Custom AI tools:
- GET /tools
- POST /tools
- GET /tools/{toolId}
- PATCH /tools/{toolId}
- DELETE /tools/{toolId}
- POST /tools/{toolId}/test
- GET /tools/logs
- GET /tools/logs/{logId}

Codex Prompt

Build a TypeScript backend client for Visito's M2M API.

Base URL: https://api.visitoai.com/m2m/v1
Auth header: Authorization: Bearer process.env.VISITO_M2M_TOKEN

Implement:
1. listChannels(): GET /channels
2. listConversations(params): GET /conversations
3. getConversation(conversationId): GET /conversations/{conversationId}
4. sendReply(conversationId, body, idempotencyKey):
   POST /conversations/{conversationId}/reply
5. listWhatsappTemplates(channelId): GET /whatsapp-templates/{channelId}
6. sendWhatsappTemplate(channelId, body, idempotencyKey):
   POST /whatsapp-templates/{channelId}/send

Requirements:
- keep token server-side only
- require Idempotency-Key for sendReply and sendWhatsappTemplate
- parse JSON error responses with error.code and error.message
- retry 429 and 5xx with exponential backoff
- do not retry 400, 401, 403, or 404
- return typed queued responses for 202 sends

CRM Automation Prompt

Create a CRM sync job using Visito's M2M API.

Flow:
1. GET /channels and find the WhatsApp channel to use.
2. GET /conversations?limit=50 to sync the current work queue.
3. GET /conversations/{conversationId} before acting on a conversation.
4. If a human-approved outbound template should be sent:
   - GET /whatsapp-templates/{channelId}
   - choose an APPROVED template by name and language
   - POST /whatsapp-templates/{channelId}/send with Idempotency-Key

Output:
- typed API client
- durable idempotency key strategy
- execution log with conversationId, replyId, requestEventId, status, and error code
- unit tests for success, 429 retry, insufficient scope, and duplicate idempotency replay

Custom Tools Prompt

Register a Visito custom AI tool for my backend.

Tool:
- name: check_availability
- description: Check available rooms for a date range and guest count.
- method: POST
- endpoint URL: https://example.com/visito/tools/check-availability
- auth: X-Tool-Key header from process.env.VISITO_TOOL_KEY
- parameters: JSON Schema with checkIn, checkOut, and guests

Use:
- POST /tools to create the tool
- POST /tools/{toolId}/test to verify it
- GET /tools/logs?toolId={toolId} for diagnostics

Requirements:
- do not log secrets
- validate tool input before calling Visito
- return concise JSON from my backend endpoint
- include tests for the generated route handler

Safety Checklist

  • Store VISITO_M2M_TOKEN in server-side secret storage.
  • Do not paste production tokens into assistant prompts.
  • Give the integration only the scopes it needs.
  • Use deterministic idempotency keys for replies and template sends.
  • Check template status before sending; only APPROVED templates can be sent.
  • Log Visito error.code, conversationId, replyId, and requestEventId for support.