← Ibisobanuro

βœ‰οΈ Ibisobanuro bya Email API

Ohereza email ku biyandikishije bawe ukoresheje SMTP yawe, nta serivisi y'undi. Abiyandikisha batanga email yabo bakayemeza (double opt-in), kandi buri email ifite link yo kuva ku rutonde.

1. Shyiraho SMTP

Shyiraho izi environment variables (aho ukorera muri .env.local, no kuri Vercel: Settings β†’ Environment Variables, hanyuma Redeploy). Iyo zitabaye zihari, PushHub ikoresha lib/server/smtp-config.js. Kuri Gmail koresha App Password, si ijambobanga risanzwe.

.env.local / Vercel
SMTP_HOST=smtp.gmail.com
SMTP_PORT=465
SMTP_USER=you@example.com
SMTP_PASS=your-app-password
SMTP_FROM=you@example.com

2. Uko abantu biyandikisha bakoresheje email

Umuntu yandika email ye, agahabwa email yo kwemeza, hanyuma akaba uwemejwe amaze gukanda buto. Shyira iyi form ku rubuga rwawe (cyangwa uhamagare REST endpoint ubwayo):

html
<form id="email-form">
  <input type="email" id="email" placeholder="you@example.com" required>
  <button type="submit">Subscribe</button>
  <p id="msg"></p>
</form>

<script src="https://push.newtalentsg.co.rw/sdk.js"></script>
<script>
  document.getElementById('email-form').addEventListener('submit', function (e) {
    e.preventDefault();
    PushHub.subscribeEmail(document.getElementById('email').value, {
      publicKey: 'pk_xxxxxxxxxxxxxxxx',
      externalId: 'user-123',      // optional
      tags: ['news'],              // optional
      lang: 'en'                   // optional: rw | en | fr
    })
      .then(function () { document.getElementById('msg').textContent = 'Check your inbox to confirm!'; })
      .catch(function (err) { document.getElementById('msg').textContent = err.message; });
  });
</script>
javascript
// Nta SDK: REST gusa
fetch('https://push.newtalentsg.co.rw/api/v1/email/subscribe', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ publicKey: 'pk_xxxxxxxx', email: 'someone@example.com', lang: 'rw' }),
}).then(r => r.json()).then(console.log);   // { success: true, status: "pending" }

Paji yo kwiyandikishaho yiteguye

Nta code ukeneye: sangiza iyi link. Yerekana form yoroshye mu rurimi rw'umusuye.

url
https://push.newtalentsg.co.rw/subscribe/pk_xxxxxxxxxxxxxxxx

3. Ohereza email

Koresha urufunguzo rw'ibanga (sk_) kuri seriveri yawe. Koresha audience "subscribers" kugira ngo ugere ku biyandikishije bemeje (igisubizo gitanga nextOffset kugeza bose bagezweho), cyangwa "to" ku ma aderesi yihariye.

curl β€” subscribers
curl -X POST https://push.newtalentsg.co.rw/api/v1/email/send \
  -H "Authorization: Bearer sk_xxxxxxxxxxxxxxxxxxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "audience": "subscribers",
    "subject": "Amakuru mashya",
    "template": "newsletter",
    "data": {
      "title": "Amakuru y'ukwezi",
      "message": "Muraho!\nDore ibyabaye uku kwezi.",
      "buttonText": "Soma byose",
      "buttonUrl": "https://example.com/blog",
      "imageUrl": "https://example.com/cover.jpg",
      "accent": "#10b981"
    }
  }'
curl β€” to
curl -X POST https://push.newtalentsg.co.rw/api/v1/email/send \
  -H "Authorization: Bearer sk_xxxxxxxxxxxxxxxxxxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "to": ["someone@example.com"],
    "subject": "Welcome!",
    "template": "welcome",
    "data": { "title": "Welcome aboard", "message": "We are happy to have you." }
  }'
curl β€” html
curl -X POST https://push.newtalentsg.co.rw/api/v1/email/send \
  -H "Authorization: Bearer sk_xxxxxxxx" -H "Content-Type: application/json" \
  -d '{ "to": ["someone@example.com"], "subject": "Custom", "html": "<h1>Hello</h1><p>Your own HTML.</p>" }'
json β€” newsletter
{
  "audience": "subscribers",
  "subject": "Amakuru y'ukwezi",
  "template": "newsletter",
  "data": {
    "kicker": "Ukwakira 2026",
    "title": "Amakuru y'ukwezi",
    "subtitle": "Ibyaranze ikigo cyacu",
    "message": "Muraho! Dore **incamake** y'ukwezi. [Soma ibisobanuro](https://example.com/docs)",
    "imageUrl": "https://example.com/cover.jpg",
    "imageAlt": "Ibirori by'ukwezi",
    "imageCaption": "Ibirori by'ukwezi",
    "cards": [
      { "kind": "article", "title": "Imbonerahamwe nshya", "text": "Twongeyeho templates.",
        "imageUrl": "https://example.com/a.jpg", "buttonText": "Soma byose", "buttonUrl": "https://example.com/blog/1" },
      { "kind": "notice", "title": "Icyitonderwa", "text": "Ibiro bizafunga ku wa gatanu." }
    ],
    "links": [
      { "url": "https://example.com/guide", "title": "Ubuyobozi", "description": "Uko ushyira PushHub ku rubuga.",
        "imageUrl": "https://example.com/thumb.jpg" }
    ],
    "buttonText": "Sura urubuga", "buttonUrl": "https://example.com",
    "company": { "website": "https://example.com", "phone": "+250 788 000 000",
                 "social": { "facebook": "https://facebook.com/acme" } }
  }
}
node.js
// Node.js 18+ β€” kohereza ku biyandikishije bose, ukurikije nextOffset
let offset = 0;
do {
  const res = await fetch('https://push.newtalentsg.co.rw/api/v1/email/send', {
    method: 'POST',
    headers: {
      Authorization: 'Bearer ' + process.env.PUSHHUB_SECRET_KEY,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      audience: 'subscribers',
      tags: ['news'],                 // optional
      subject: 'Hello',
      template: 'announcement',
      data: { title: 'Big news', message: 'Something new is live.' },
      offset,
    }),
  });
  const j = await res.json();
  console.log(j);
  offset = j.nextOffset;               // null iyo birangiye
} while (offset != null);
response (200)
{
  "success": true,
  "total": 230,        // abiyandikishije bose bahuye n'ubusabe
  "recipients": 100,   // abo muri iki cyifuzo
  "sent": 99,
  "failed": 1,
  "nextOffset": 100    // null iyo nta bandi basigaye
}

4. Templates

Hitamo imwe mu rwego rwa template, wuzuze data. Template zose zisangiye header (logo ibumoso, izina ry'ikigo hagati), body na footer. Cyangwa wohereze html yawe bwite.

πŸ‘‹welcomeIndamutso ifite umutwe w'ibara na buto.
πŸ“°newsletterIzina ry'ikigo, ishusho (si ngombwa), umutwe n'inyandiko.
πŸ“’announcementUmurongo w'ibara n'itangazo rinini.
πŸŽ‰promoIgishushanyo cy'umwijima gishyizwe hagati, cy'ibigabanyirizwa.
βœ‰οΈsimpleEmail y'inyandiko yoroshye nta bishushanyo.

Imirima ya data

titleUmutwe.
subtitleUmutwe muto munsi y'umutwe.
kickerAkazina gato hejuru y'umutwe (newsletter).
messageInyandiko y'ubutumwa. Yemera **bold**, *italic* na [label](https://link); umurongo urimo ubusa utangiza paragarafu nshya.
buttonTextInyandiko iri kuri buto.
buttonUrlLink ya buto (https://...).
imageUrlAderesi y'ishusho (si ngombwa).
imageAltAlt text y'ishusho nkuru.
imageCaptionIbisobanuro munsi y'ishusho nkuru.
imagesAndi mashusho: [{ url, alt, caption, link }] (6 ntarengwa, HTTPS).
linksAmakarita ya link: [{ url, title, description, imageUrl }] (6 ntarengwa). Hagaragara ibyo watanze gusa; nta metadata ivanwa hanze cyangwa ihimbwa.
cardsIbice by'ibikubiyemo: [{ kind: article | announcement | promo | service | notice, title, text, imageUrl, buttonText, buttonUrl }] (8 ntarengwa).
highlightInyandiko nini y'igabanyirizwa (promo), urugero -30%.
codeKode y'igabanyirizwa igaragara mu gasanduku k'utudomo.
accentIbara nka #10b981.
footerInyandiko yo hasi (si ngombwa).
companyIsimbura amakuru y'ikigo kuri iyi email (website, email, phone, address, privacyUrl, preferencesUrl, logoUrl, social).

Parameters za /api/v1/email/send

IzinaIbisobanuro
toUrutonde rwa aderesi za email (100 ntarengwa).
audience"subscribers" kugira ngo wohereze ku biyandikishije bemeje.
externalIdsHamwe na audience: externalId izi gusa.
tagsHamwe na audience: abafite imwe muri tags izi gusa.
subjectUmutwe w'email (ngombwa).
templatewelcome | newsletter | announcement | promo | simple.
dataIbikubiye muri template (reba hejuru). Bisaba title cyangwa message.
htmlHTML yawe bwite (mu cyimbo cya template).
textVerisiyo y'inyandiko isanzwe.
replyToAderesi yo gusubizaho (Reply-To).
langrw | en | fr β€” ururimi rw'amagambo yo kuva ku rutonde.
offsetAho gutangirira mu matsinda (koresha nextOffset).
limitAbiyandikishije kuri buri cyifuzo (100 ntarengwa).

5. Imimerere y'uwiyandikishije no kuva ku rutonde

pending = itegereje kwemezwa, active = yakira email, unsubscribed = yavuyeho akoresheje link iri hasi ya buri email. Abakira email ni abari active gusa.

6. Header, logo na footer

Buri email ifite header (logo ibumoso, izina ry'ikigo hagati) na footer (itumanaho ryemewe, uko bavugana, imbuga nkoranyambaga, politiki y'ibanga, link yo kuva ku rutonde, copyright). Shyira logo yawe kuri public/logo.png (cyangwa ushyireho EMAIL_LOGO_URL, cyangwa aderesi ya logo muri tab y'Ikigo). Iyo nta logo ihari, haboneka akadirishya karimo inyuguti ya mbere y'izina ry'ikigo. Uzuza amakuru y'ikigo muri dashboard (Email β†’ Ikigo).

7. Kugera muri inbox no kuva ku rutonde ukanze rimwe

Email zoherezwa ku biyandikishije zifite headers List-Unsubscribe na List-Unsubscribe-Post (RFC 8058), bityo Gmail na Apple Mail byerekana buto yabyo yo kuva ku rutonde. Footer ntivuga ko hari igenzura ryakozwe: kugira ngo email zidajya muri spam, shyiraho SPF, DKIM na DMARC kuri domain yoherezaho.

Amakosa asanzwe

401invalid_secret_key / invalid_public_key
400subject_required / to_or_audience_required / invalid_email / invalid_template / template_data_required / content_required / too_many_recipients / invalid_link
502email_failed
500smtp_not_configured / server_error

Iby'ingenzi

  • Gmail yemera email zigera kuri 500 ku munsi; ku zirenze koresha SMTP ya domain yawe.
  • Kugira ngo email zidajya muri spam, shyiraho SPF na DKIM kuri domain yoherezaho.
  • Buri cyifuzo cyohereza email 100 ntarengwa; subiramo ukoresheje nextOffset kugeza ku bantu bose.
  • Ntuzigere ushyira urufunguzo rw'ibanga (sk_) muri code ya frontend.