Sending OTPs
Use sendOtp() for login codes, verification codes, and one-time passwords.
Basic OTP
TypeScript
await client.sendOtp({
to: '+918851479441',
template: 'test_welcome_template',
code: '123456',
});
The SDK places code as the first body_params value, then appends any extraParams. The server maps these to the template's {{1}}, {{2}} placeholders.
With Extra Parameters
If your template has more placeholders beyond the OTP code:
TypeScript
await client.sendOtp({
to: '+918851479441',
template: 'test_welcome_template',
code: '654321',
extraParams: ['Acme Corp'], // fills {{2}} in the template
});
cURL Equivalent
bash
curl -X POST https://api.convoup.com/api/v1/templates \
-H "Content-Type: application/json" \
-H "x-api-key: YOUR_API_KEY" \
-d '{
"to": "+918851479441",
"template_name": "test_welcome_template",
"language": "en_US",
"body_params": [{"type": "text", "text": "123456"}]
}'
How It Works Internally
- The SDK takes your
codeand places it asbody_params[0] - Any
extraParamsare appended asbody_params[1],body_params[2], etc. - The server maps these to the template's
{{1}},{{2}}placeholders - The final payload is sent to the Meta WhatsApp Cloud API
Response
JSON
{
"messageId": "meta-msg-abc123",
"waId": "918851479441"
}
Error Handling
TypeScript
import { Convoup, ConvoupError } from 'convoup';
try {
await client.sendOtp({
to: '+918851479441',
template: 'test_welcome_template',
code: '123456',
});
} catch (err) {
if (err instanceof ConvoupError) {
if (err.code === 'TEMPLATE_NOT_FOUND') {
console.error('Template not found. Create it in the Convoup dashboard.');
} else if (err.code === 'TEMPLATE_PARAM_MISMATCH') {
console.error('Param mismatch:', err.message);
}
}
}
Next Steps
- Sending Invoices - Send invoices with PDF attachments
- Bulk Sending - Send OTPs to multiple customers
- Error Codes - Handle all error scenarios
