Sending messages
Every send returns as soon as MsGine has accepted the message, with its id, status and cost in UGX. Every send also accepts scheduledFor (an ISO 8601 time to send later) and an idempotencyKey (see Errors and retries).
SMS
await msgine.sms.send({
to: ['+256701234567', '+256772345678'],
message: 'Your order A-1042 is on its way.',
from: 'MyShop',
});msgine.sms.send(
to=["+256701234567", "+256772345678"],
message="Your order A-1042 is on its way.",
from_="MyShop",
)client.SMS.Send(ctx, msgine.SendSMSParams{
To: []string{"+256701234567", "+256772345678"},
Message: "Your order A-1042 is on its way.",
From: "MyShop",
})from is a sender ID of up to 11 characters. Messages up to 1,000 characters are split into parts and charged per part.
WhatsApp
Free-form text reaches only people who messaged you in the last 24 hours. Outside that window, send an approved template.
await msgine.whatsapp.send({
to: '+256701234567',
templateId: 'order_update',
templateLanguage: 'en',
templateParams: ['Amina', 'A-1042'],
messageType: 'utility',
});
await msgine.whatsapp.send({ to: '+256701234567', message: 'Thanks, we have received your payment.' });msgine.whatsapp.send(
to="+256701234567",
template_id="order_update",
template_language="en",
template_params=["Amina", "A-1042"],
message_type="utility",
)
msgine.whatsapp.send(to="+256701234567", message="Thanks, we have received your payment.")client.WhatsApp.Send(ctx, msgine.SendWhatsAppParams{
To: []string{"+256701234567"},
TemplateID: "order_update",
TemplateLanguage: "en",
TemplateParams: []string{"Amina", "A-1042"},
MessageType: "utility",
})Media: set mediaUrl and mediaType (image, video, document or audio).
Messages people send you are listed by whatsapp.inbound(), newest first. To get them as they arrive, subscribe a webhook to whatsapp.received.
Email
Email is for transactional messages only: receipts, codes, alerts, and account and service notices. Send from a domain you have verified in the dashboard.
await msgine.email.send({
from: 'receipts@yourdomain.com',
to: 'customer@example.com',
subject: 'Your receipt for order A-1042',
html: '<p>Thank you for your payment of UGX 85,000.</p>',
text: 'Thank you for your payment of UGX 85,000.',
});msgine.email.send(
from_="receipts@yourdomain.com",
to="customer@example.com",
subject="Your receipt for order A-1042",
html="<p>Thank you for your payment of UGX 85,000.</p>",
text="Thank you for your payment of UGX 85,000.",
)client.Email.Send(ctx, msgine.SendEmailParams{
From: "receipts@yourdomain.com",
To: []string{"customer@example.com"},
Subject: "Your receipt for order A-1042",
HTML: "<p>Thank you for your payment of UGX 85,000.</p>",
Text: "Thank you for your payment of UGX 85,000.",
})cc and bcc take one address or a list. Bounced and complaining addresses are suppressed automatically.
Push notifications
Your app sends its Firebase device token to your backend; your backend registers it with your own ID for that user. You can then send to those user IDs (externalUserIds) or to a Firebase topic.
await msgine.push.devices.register({ token: fcmToken, platform: 'android', externalUserId: 'user_42' });
await msgine.push.send({
title: 'Parcel delivered',
body: 'Your parcel A-1042 is at the front desk.',
externalUserIds: ['user_42'],
data: { orderId: 'A-1042' },
});msgine.push.devices.register(token=fcm_token, platform="android", external_user_id="user_42")
msgine.push.send(
title="Parcel delivered",
body="Your parcel A-1042 is at the front desk.",
external_user_ids=["user_42"],
data={"orderId": "A-1042"},
)client.Push.Devices.Register(ctx, msgine.RegisterDeviceParams{Token: fcmToken, Platform: "android", ExternalUserID: "user_42"})
client.Push.Send(ctx, msgine.SendPushParams{
Title: "Parcel delivered",
Body: "Your parcel A-1042 is at the front desk.",
ExternalUserIDs: []string{"user_42"},
Data: map[string]string{"orderId": "A-1042"},
})Pushes go through MsGine's Firebase project unless you connect your own with push.config.set. When your app shows or opens a notification, report it with push.confirm(notificationId, 'delivered' | 'opened') so push history shows delivery and opens.
Histories and lookup
Every history returns items, total, page and pages, newest first.
const { items, pages } = await msgine.sms.list({ page: 1, limit: 50 });
const message = await msgine.messages.get(items[0].id);page = msgine.sms.list(page=1, limit=50)
message = msgine.messages.get(page.items[0]["id"])page, err := client.SMS.List(ctx, &msgine.PageOptions{Page: 1, Limit: 50})
message, err := client.Messages.Get(ctx, page.Items[0].ID)messages.get finds a message of any channel by its ID.