Send a message
typescript
const message = await buzzbip.messages.send({
to: '+21612345678',
type: 'text',
text: { body: 'Your order has shipped!' },
});Create or update a contact
typescript
const contact = await buzzbip.contacts.create({
phone: '+21612345678',
firstName: 'Walid',
lastName: 'Ben Ali',
tags: ['woocommerce'],
});Paginate contacts
typescript
for await (const contact of buzzbip.contacts.list({ limit: 50 })) {
console.log(contact.id, contact.phone);
}Trigger a workflow
typescript
const execution = await buzzbip.workflows.trigger('wfl_order_update', {
contactId: 'cnt_abc123',
payload: { orderId: 'ORD-9876', total: '149.00 TND' },
});Verify webhook signatures
Use the built-in helper in your Express or Next.js webhook handler:
typescript
import { BuzzBip } from '@buzzbip/sdk';
const event = BuzzBip.webhooks.constructEvent({
payload: rawBody, // Raw request body string
signature: req.headers['x-buzzbip-signature'],
secret: process.env.BUZZBIP_WEBHOOK_SECRET!,
});
switch (event.type) {
case 'message.received':
console.log(event.data.body);
break;
case 'contact.created':
console.log(event.data.contactId);
break;
}Error handling
typescript
import { BuzzBipError } from '@buzzbip/sdk';
try {
await buzzbip.messages.send({ /* ... */ });
} catch (err) {
if (err instanceof BuzzBipError) {
console.error(err.code, err.message, err.statusCode);
}
}