On Behalf of WhatsApp Sender

Before creating an OBO Sender, the project needs to have an Account.

You can verify if the project already has an onboarded account by calling the Get Account endpoint.

Copy
Copied
async function getAccount() {
  const resp = await fetch(
    `https://provisioning.api.sinch.com/v1/projects/${PROJECT_ID}/whatsapp`,
    {
      method: 'GET',
      headers: {
        'Content-Type': 'application/json',
        Authorization:
          'Basic ' +
          Buffer.from(ACCESS_KEY + ':' + ACCESS_SECRET).toString('base64'),
      },
    }
  );

  const data = await resp.json();
  return data;
}

NOTE: An account can either be compatible with OBO or ES senders. An account is automatically created as part of the ES sender creation. If the account is of the wrong type the create sender will reject the request.

Creating an Account

To create an account you will need your Facebook Manager ID as well as the Legal name of the Business. You can find your ID in the Meta Business Manager under Business Info.

Copy
Copied
async function createAccount() {
  const resp = await fetch(
    `https://provisioning.api.sinch.com/v1/projects/${PROJECT_ID}/whatsapp`,
    {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        Authorization:
          'Basic ' +
          Buffer.from(ACCESS_KEY + ':' + ACCESS_SECRET).toString('base64'),
      },
      body: JSON.stringify({
        companyLegalName: 'Company Legal Name',
        clientBusinessManagerId: 'Manager ID',
      }),
    }
  );

  const data = await resp.json();
  return data;
}

Once the Account has been created it will initially be in progress. The state transitions for the request is as follows: IN_PROGRESS -> PENDING_FACEBOOK_VERIFICATION -> ONBOARDED

At the PENDING_FACEBOOK_VERIFICATION step the "Message on Behalf Of Authority" notification needs to be approved in the Facebook Business Manager Console.

Need Help? Click here to learn how to register your WABA with Sinch.

To verify the state transitions and when the next steps are needed to be performed, you can either poll the endpoint above or register a webhook and wait for the WHATSAPP_ACCOUNT_PENDING_VERIFICATION and WHATSAPP_ACCOUNT_ONBOARDED callbacks.

Creating a Sender

Once the account is onboarded, a sender can be created. To create a sender it either requires a phone number provided or specifying that Sinch will provide a phone number.

If Sinch provides the phone number, set phoneNumberProvider to SINCH and provide details.countryCode for the desired country of the number. If the caller provides the number, set phoneNumberProvider to CUSTOMER and set both details.countryCode and details.phoneNumber.

Copy
Copied
async function createSender() {
  const resp = await fetch(
    `https://provisioning.api.sinch.com/v1/projects/${PROJECT_ID}/whatsapp/senders`,
    {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        Authorization:
          'Basic ' +
          Buffer.from(ACCESS_KEY + ':' + ACCESS_SECRET).toString('base64'),
      },
      body: JSON.stringify({
        status: 'submit',
        region: 'EU',
        phoneNumberProvider: 'CUSTOMER',
        details: {
          displayName: 'Example Sender',
          description: 'This is an example sender',
          vertical: 'NON_PROFIT',
          email: 'user@example.com',
          websiteOne: 'https://www.example.com',
          about: 'A simple example sender',
          photoUrl: 'https://www.example.com/some_image.jpg',
          countryCode: '46',
          phoneNumber: '1234123456',
        },
      }),
    }
  );

  const data = await resp.json();
  return data;
}

Once created, the sender will be in state IN_PROGRESS. After a review it is possible the sender will be rejected and will then have state REJECTED. The notifications endpoint can be used to see if there is a comment explaining the reason for the rejection. If REJECTED, the sender can be edited and submitted again.

Verifying Sender

NOTE If Sinch provides the phone number, then this section can be skipped as the phone number will be verified by Sinch.

Once the sender reaches the PENDING_VERIFICATION state the phone number needs to be verified. Start the process by triggering the Register sender endpoint while providing either SMS or VOICE as the verification method.

Copy
Copied
async function registerSender() {
  const resp = await fetch(
    `https://provisioning.api.sinch.com/v1/projects/${PROJECT_ID}/whatsapp/senders/${SENDER_ID}/register`,
    {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        Authorization:
          'Basic ' +
          Buffer.from(ACCESS_KEY + ':' + ACCESS_SECRET).toString('base64'),
      },
      body: JSON.stringify({
        method: 'SMS',
      }),
    }
  );

  const data = await resp.json();
  return data;
}

Once the OTP code has been received, verify the sender with the code.

Copy
Copied
async function verifySender() {
  const resp = await fetch(
    `https://provisioning.api.sinch.com/v1/projects/${PROJECT_ID}/whatsapp/senders/${SENDER_ID}/verify`,
    {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        Authorization:
          'Basic ' +
          Buffer.from(ACCESS_KEY + ':' + ACCESS_SECRET).toString('base64'),
      },
      body: JSON.stringify({
        code: '123456',
      }),
    }
  );

  const data = await resp.json();
  return data;
}

The sender will continue through the state transitions and eventually become active. Once active, you can create templates for the sender.

State transitions for OBO Senders

DRAFT
IN_PROGRESS
REJECTED
PENDING_VERIFICATION
ACTIVE
SUSPENDED
INACTIVE
Only if customer supplied phone number.
Will stay in INACTIVE for up to 30 days. Accounts can become inactive while migrating a phone number.