KakaoTalk templates

KakaoTalk templates can be created for any project with a registered Sender.

Note that, for this guide, we provide Node.js code samples. However, the principles apply to any language you use to make requests to the API.

Creating a template

The following code sample creates a KakaoTalk template using the Provisioning API.

Copy
Copied
import fetch from 'node-fetch';

async function createTemplate() {
  const resp = await fetch(
    `https://provisioning.api.sinch.com/v1/projects/${PROJECT_ID}/kakaotalk/senders/${PLUS_FRIEND_ID}/templates`,
    {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        Authorization:
          'Basic ' +
          Buffer.from(ACCESS_KEY + ':' + ACCESS_SECRET).toString('base64'),
      },
      body: JSON.stringify({
        status: 'SUBMIT',
        details: {
          language: 'EN',
          messageType: 'BASIC',
          emphasizeType: 'EMPHASIZE_TYPE_NONE',
          categoryCode: '001001',
          securityFlag: false,
          name: 'Example name',
          content: 'Example content',
          extra: 'Example extra',
          title: 'Example title',
          subtitle: 'Example subtitle',
          imageName: 'Example image name',
          imageUrl: 'https://example-image-url.com',
          buttons: [
            {
              ordering: 1,
              type: 'APP_LINK',
              name: 'Example Name',
              linkMo: 'https://example-link-mo.com',
              linkPc: 'https://example-link-pc.com',
              schemeIos: 'https://example-scheme-ios.com',
              schemeAndroid: 'https://example-scheme-android.com',
            },
          ],
        },
      }),
    }
  );

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

Note that, within the details object, the language, name, and content fields are all required. For more information on the other fields included in this example, see the API reference.

After creating a template, you can view it (and others) by using the list templates operation.

Listing templates

Use the list templates operation in a project to see a paginated list of templates for the specified project, including templates that are in progress.

The list is paginated, and the response will include a nextPageToken field if more pages are available.

Copy
Copied
import fetch from 'node-fetch';

async function getAllApprovedTemplates(pageToken: string) {
  const resp = await fetch(
    `https://provisioning.api.sinch.com/v1/projects/${PROJECT_ID}/kakaotalk/senders/${PLUS_FRIEND_ID}/templates?pageToken=${pageToken}`,
    {
      method: 'GET',
      headers: {
        'Content-Type': 'application/json',
        Authorization:
          'Basic ' +
          Buffer.from(ACCESS_KEY + ':' + ACCESS_SECRET).toString('base64'),
      },
    }
  );

  let data = await resp.json();

  if (data.nextPageToken) {
    const nextData = await getAllApprovedTemplates(data.nextPageToken);

    return {
      ...data.templates,
      ...nextData.templates,
    };
  } else {
    return data.templates;
  }
}

The state of the returned template(s) will either be APPROVED or REJECTED. Additionally, the status field of the changes object will indicate the current status of changes applied to the draft (one of IN_PROGRESS, REJECTED, or DRAFT).