Skip to content
Last updated

Embedded creation for WhatsApp Multi-Partner Solution

Multi-Partner Solution (MPS) creation allows for a Tech Provider (TP) to create an MPS. This enables the creation of new WhatsApp senders through Embedded Signup (ES) together with Sinch as Solution Partner (SP).

This can be achieved via Sinch Build, or by following these instructions:

Generate Access Token

An access token can be generated using an embedded create button for MPS creation:

<!-- Load JavaScript SDK asynchronously -->
<script async defer crossorigin="anonymous" src="https://connect.facebook.net/en_US/sdk.js"></script>

<script>
  // Configure JavaScript SDK
  window.fbAsyncInit = function() {
    FB.init({
      appId: "<SOLUTION_PARTNER_APP_ID>", // Replace with your app ID
      cookie: true,
      xfbml: true,
      version: "v20.0"
    });
  };

  // Launch MPS creation flow
  function launchSolutionCreationFlow() {
    FB.login(
      function (response) {
        if (response.authResponse) {
          const accessToken = response.authResponse.accessToken;
          console.log(accessToken); // Replace with your code that captures access token
        } else {
          console.log("User failed to authorize"); // Replace with your code that logs auth failure
        }
      },
      {
        scope: "manage_app_solution"
      }
    );
  }
</script>

<button onclick="launchSolutionCreationFlow()" style="background-color: #1877f2; border: 0; border-radius: 4px; color: #fff; cursor: pointer; font-family: Helvetica, Arial, sans-serif; font-size: 16px; font-weight: bold; height: 40px; padding: 0 24px;">Launch Solution Creation</button>

The script will generate response from Meta:

{
  status: 'connected',
  authResponse: {
    accessToken: '<USER_ACCESS_TOKEN>',
    expiresIn:'<TOKEN_EXPIRATION_TIMESTAMP>',
    reauthorize_required_in:'<SECONDS_UNTIL_REAUTH_REQUIRED>',
    signedRequest:'<SIGNED_PARAMETER>',
    userID:'<USER_ID>'
  }
}

Please refer to Meta documentation for more information about this step.

Next, the access token will be used to create a Solution.

Create a Solution

Use Provisioning API Create Solution endpoint to create a Solution by providing the access token (accessToken).

async function createSolution() {
  const resp = await fetch(
    `https://provisioning.api.sinch.com/v1/projects/${PROJECT_ID}/whatsapp/solutions`,
    {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        Authorization:
          'Basic ' +
          Buffer.from(ACCESS_KEY + ':' + ACCESS_SECRET).toString('base64'),
      },
      body: JSON.stringify({
        accessToken: ACCESS_TOKEN,
        businessManager: 'SINCH_UK',
        details: {
          name: 'Test name',
        },
      }),
    }
  );

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

The response to this request will return all created Solutions as a list. This list can later be retrieved using the List Solutions endpoint.

Next, a Solution will be assigned to the project to enable ES Sender creation.

Assign Solution to Project

Use Provisioning API to assign the Solution to the Project:

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

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

Once a Solution has been assigned to the project, it's possible to create Senders using the ES flow.