페이지 이동경로
  • Docs>
  • Kakao Talk Message>
  • Flutter

Kakao Talk Message

Flutter

This document describes how to integrate Kakao Talk Message APIs into your service with the Kakao SDK for Flutter ("Flutter SDK").

The Kakao Talk Message API only supports sending messages between users within the same service, and the Kakao Talk Social API permission is required to provide the message sending feature to friends. For more details, see Message sending features and How to use.

Before you begin

Choose implementation method

1. Select message sending feature

Kakao Developers provides two types of message sending features: Kakao Talk Share and Kakao Talk Message. Refer to Message sending features to select the feature to use. If you want to use Kakao Talk Message, perform the following steps.

2. Select message type and configuration method

Refer to Template types to decide which message template to use.

Refer to Configuration method comparison to decide how to configure messages. You can use default templates based on predefined templates in object form, or custom templates configured directly for your service.

3. Select message target

Note that for Kakao Talk Message, the APIs used are distinguished according to the message targets.

Target Description
Send to me Sends a message to the "Me" chat in Kakao Talk of the currently logged-in user. This feature cannot send messages to other users and can only send messages to the logged-in user themselves.
Send to friends Sends a message to friends in Kakao Talk of the currently logged-in user.
Important: Additional feature request is required.
You must implement a process to receive recipient information through Retrieve friends through picker API or Retrieve friends through picker API. You can send messages to up to 5 friends at once. Daily and monthly quotas are set, so refer to Quota.
Note: Permission Required

If you want to send messages to friends, you must request permission. See Usage policy.


Project Setting

To use the Kakao Talk Message API on the native app service, you must set the Custom URL Scheme. See how to set up a project by device environment below.

Send me message with default template

Basic information
Reference App setting
sendDefaultMemo()
FeedTemplate
ListTemplate
LocationTemplate
CommerceTemplate
TextTemplate
MessageSendResult
MessageFailureInfo
Install
Initialize
Project Setting
Permission Prerequisite Kakao Login User consent
- Register platforms
Activate Kakao Login
Manage consent items
Required Required:
Send message in Kakao Talk (talk_message)

This is an API that sends a message to me by defining components as objects according to predefined template formats. For detailed message configuration methods, see Default template.

Request

To create a message, implement the DefaultTemplate interface, then use one of the following classes according to the desired template type to configure template objects.

When calling sendDefaultMemo(), pass the template object as the template parameter.

Response

When message transmission fails, it returns a response code. See Error code to identify the cause of failure with code and msg.

Example

try {
  await TalkApi.instance.sendDefaultMemo(defaultFeed);
  print('Succeeded in sending me a message.');
} catch (error) {
  print('Failed to send me a message. $error');
}

Send me message with custom template

Basic information
Reference App setting
sendCustomMemo()
MessageSendResult
MessageFailureInfo
Install
Initialize
Project Setting
Permission Prerequisite Kakao Login User consent
- Register platforms
Activate Kakao Login
Manage consent items
Message template
Required Required:
Send message in Kakao Talk (talk_message)

This is an API that sends messages using custom templates directly configured in [Tools] > [Message Template]. For message configuration methods, see Custom template.

Request

When calling sendCustomMemo(), you must pass the template ID confirmed in the message template tool as the templateId parameter.

To include variable information in messages, add user arguments to the corresponding custom template, then pass keys and values as the templateArgs parameter. If you do not use this parameter even though the custom template includes user arguments, the part specified as user arguments will be exposed in the message as ${KEY} format.

Response

When message transmission fails, it returns a response code. See Error code to identify the cause of failure with code and msg.

Example

// Custom template ID
int templateId = '${YOUR_CUSTOM_TEMPLATE_ID}';

try {
  await TalkApi.instance.sendCustomMemo(templateId: templateId);
  print('Succeeded in sending me a message.');
} catch (error) {
  print('Failed to send me a message. $error');
}

Send me scrape message

Basic information
Reference App setting
sendScrapMemo()
FeedTemplate
ListTemplate
LocationTemplate
CommerceTemplate
TextTemplate
MessageSendResult
MessageFailureInfo
Install
Initialize
Project Setting
Permission Prerequisite Kakao Login User consent
- Register platforms
Activate Kakao Login
Manage consent items
Required Required:
Send message in Kakao Talk
(talk_message)

This API configures a scrape message with information scraped from a specified web page and sends a message to the currently logged-in user's Kakao Talk.

Request

To send a Kakao Talk message to the user's My Chatroom by scrapping a web page, call the sendScrapMemo() method in the TalkApi class. You must pass url when calling this method.

Response

When message transmission fails, it returns a response code. See Error code to identify the cause of failure with code and msg.

Example: Using default template

// Web page URL to be shared.
//  * Caution: The domain of the URL to be shared must be registered in [My Appliction] > [Platform] > [Web] in Kakao Developers.
String url = 'https://developers.kakao.com';

try {
  await TalkApi.instance.sendScrapMemo(url: url);
  print('Succeeded in sending me a message');
} catch (error) {
  print('Failed to send me a message. $error');
}

Example: Using custom template

// Custom template ID
int templateId = '${YOUR_CUSTOM_TEMPLATE_ID}';

try {
  await TalkApi.instance.sendScrapMemo(url: url);
  print('Succeeded in sending me a message.');
} catch (error) {
  print('Failed to send me a message. $error');
}

Send friends message with default template

Basic information
Reference App setting
sendDefaultMessage()
FeedTemplate
ListTemplate
LocationTemplate
CommerceTemplate
TextTemplate
MessageSendResult
MessageFailureInfo
Install
Initialize
Project Setting
Permission Prerequisite Kakao Login User consent
Required:
Permission
Register platforms
Activate Kakao Login
Manage consent items
Required Required:
Send message in Kakao Talk (talk_message)

This API sends a message to the currently logged-in user's Kakao Talk using default templates.

Request

  1. Configure message template: To create a message, implement the DefaultTemplate interface, then use one of the following classes according to the desired template type to configure template objects.
  2. Retrieve message recipients: To send a message to friends, you must determine who to send the message to. First, call the Retrieve friends through picker API or Retrieve list of friends API to get the uuid information of friends to send messages to.
  3. Specify template and recipients: When calling sendDefaultMessage(), pass the previously configured template object as the template parameter, and pass the list of uuids of friends selected by the user as the receiverUuids parameter. You can send messages to up to 5 friends at once.

Response

The message transmission result is returned as a MessageSendResult object. When message transmission succeeds, successfulReceiverUuids contains a list of uuids of friends who successfully received the message. When message transmission fails for some friends, failureInfos contains failure information. See Error code to identify the cause of failure with code and msg.

Example

// Retrieve a list of Kakao Talk friends.
Friends friends;
try {
  friends = await TalkApi.instance.friends();
} catch (error) {
  print('Failed to retrieve a list of friends. $error');
  return;
}

if (friends.elements == null) {
  return;
}

if (friends.elements!.isEmpty) {
  print('There is no friend to send a message to :(');
} else {
  // Retrieve UUIDs of the friends to send a message according to your service's environment.
  // This sample displays the Friends list and collects the UUIDs of the friends selected by a user.
  List<String> selectedItems = await Navigator.of(context).push(
  MaterialPageRoute(
    builder: (context) => FriendPage(
    items: friends.elements!
      .map((friend) => PickerItem(
        friend.uuid,
        friend.profileNickname ?? '',
        friend.profileThumbnailImage))
      .toList(),
      ),
    ),
  );

  if (selectedItems.isEmpty) {
    return;
  }
  print('Selected friends:\n${selectedItems.join('\n')}');

  // List of UUIDs of recipients to send a message to.
  List<String> receiverUuids = selectedItems;

  // Feed message
  FeedTemplate template = defaultFeed;

  // Send a Feed message
  try {
  MessageSendResult result =
    await TalkApi.instance.sendDefaultMessage(
    receiverUuids: receiverUuids,
    template: template,
  );
  print('Succeeded in sending a message to ${result.successfulReceiverUuids}.');

  if (result.failureInfos != null) {
      print('Succeed! But failed to send a message to some friends: \n${result.failureInfos}');
  }
  } catch (error) {
  print('Failed to send a message. $error');
  }
}

Send friends message with custom template

Basic information
Reference App setting
sendCustomMessage()
MessageSendResult
MessageFailureInfo
Install
Initialize
Project Setting
Permission Prerequisite Kakao Login User consent
Required:
Permission
Register platforms
Activate Kakao Login
Manage consent items
Message template
Required Required:
Send message in Kakao Talk (talk_message)

This is an API that sends messages using custom templates directly configured in [Tools] > [Message Template]. For message configuration methods, see Custom template.

Request

  1. Retrieve message recipients: To send a message to friends, you must determine who to send the message to. First, call the Retrieve friends through picker API or Retrieve list of friends API to get the uuid information of friends to send messages to. Pass the list of uuids of friends selected by the user as the receiverUuids parameter. You can send messages to up to 5 friends at once.
  2. Pass template ID: When calling sendCustomMessage(), you must pass the template ID confirmed in the message template tool as the templateId parameter.
  3. Pass user arguments (optional): To include variable information in messages, add user arguments to the corresponding custom template, then pass keys and values as the templateArgs parameter. If you do not use this parameter even though the custom template includes user arguments, the part specified as user arguments will be exposed in the message as ${KEY} format.

Response

The message transmission result is returned as a MessageSendResult object. When message transmission succeeds, successfulReceiverUuids contains a list of uuids of friends who successfully received the message. When message transmission fails for some friends, failureInfos contains failure information. See Error code to identify the cause of failure with code and msg.

// Retrieve a list of friends.
Friends friends;
try {
  friends = await TalkApi.instance.friends();
} catch (error) {
  print('Failed to retrieve a list of friends. $error');
  return;
}

if (friends.elements == null) {
  return;
}

if (friends.elements!.isEmpty) {
  print('There is no friend to send a message to :(');
} else {
  // Retrieve UUIDs of the friends to send a message according to your service's environment.
  // This sample displays the Friends list and collects the UUIDs of the friends selected by a user.
  List<String> selectedItems = await Navigator.of(context).push(
    MaterialPageRoute(
        builder: (context) => FriendPage(
        items: friends.elements!
            .map((friend) => PickerItem(
            friend.uuid,
            friend.profileNickname ?? '',
            friend.profileThumbnailImage))
            .toList(),
        ),
    ),
  );

  if (selectedItems.isEmpty) {
    return;
  }
  print('Selected friends:\n${selectedItems.join('\n')}');

  // List of UUIDs of recipients to send a message to
  List<String> receiverUuids = selectedItems;

  // Custom template ID
  int templateId = '${YOUR_CUSTOM_TEMPLATE_ID}';

  // Send a message with custom template
  try {
  MessageSendResult result = await TalkApi.instance.sendCustomMessage(
    receiverUuids: receiverUuids,
    templateId: templateId,
  );
  print('Succeeded in sending a message to ${result.successfulReceiverUuids}.');

  if (result.failureInfos != null) {
    print('Succeed! But failed to send a message to some friends: \n${result.failureInfos}');
  }
  } catch (error) {
  print('Failed to send a message. $error');
  }
}

Send friends scrape message

Basic information
Reference App setting
sendScrapMessage()
FeedTemplate
ListTemplate
LocationTemplate
CommerceTemplate
TextTemplate
MessageSendResult
MessageFailureInfo
Install
Initialize
Project Setting
Permission Prerequisite Kakao Login User consent
Required:
Permission
Register platforms
Activate Kakao Login
Manage consent items
Required Required:
Send message in Kakao Talk
(talk_message)

This API configures a scrape message with information scraped from a specified web page and sends a message to friends.

Request

  1. Retrieve message recipients: To send a message to friends, you need to determine who to send the message to. First, call the Retrieve friends through picker API or Retrieve list of friends API to get the uuid information of friends to send messages to.
  2. Specify web page URL to scrape: When calling sendScrapMessage(), you must pass the URL of the web page to scrape as the url parameter. The domain of the web page to scrape must be registered in [My Application] > [Platform] > [Web] in the app management page.
  3. Apply custom template (optional): If you want to send a scrape message based on a message template defined in your service, you must pass the template ID configured in [Tools] > [Message Template] as the templateId parameter. For template configuration methods, see Custom template. To include variable information in messages, use user arguments. In this case, you must pass keys and values as the templateArgs parameter.

Response

The message transmission result is returned as a MessageSendResult object. When message transmission is successful, successfulReceiverUuids contains a list of uuids of friends who successfully received the message. When message transmission fails for some friends, failure information is included in failureInfos. Refer to Error code to check the failure cause using code and msg.

Example: Using default template

// Sending friends a message by scrapping a web page

// Retrieving a list of friends.
Friends friends;
try {
  friends = await TalkApi.instance.friends();
} catch (error) {
  print('Failed to retrieve a list of friends. $error');
  return;
}

if (friends.elements == null) {
  return;
}

if (friends.elements!.isEmpty) {
  print('There is no friend to send a message to :(');
} else {
  // Retrieve UUIDs of the friends to send a message according to your service's environment.
  // This sample displays the Friends list and collects the UUIDs of the friends selected by a user.
  List<String> selectedItems = await Navigator.of(context).push(
    MaterialPageRoute(
        builder: (context) => FriendPage(
        items: friends.elements!
        .map((friend) => PickerItem(
        friend.uuid,
        friend.profileNickname ?? '',
        friend.profileThumbnailImage))
        .toList(),
        ),
    ),
  );

  if (selectedItems.isEmpty) {
  return;
  }
  print('Selected friends:\n${selectedItems.join('\n')}');

  // List of UUIDs of recipients to send a message to
  List<String> receiverUuids = selectedItems;

  // Web page URL to be shared
  //  * Caution: The domain of the URL to be shared must be registered in [My Appliction] > [Platform] > [Web] in Kakao Developers.
  String url = "https://developers.kakao.com";

  // Sending a scrape message
  try {
  MessageSendResult result = await TalkApi.instance.sendScrapMessage(
    receiverUuids: receiverUuids,
    url: url,
  );
  print('Succeeded in sending a message to ${result.successfulReceiverUuids}.');

  if (result.failureInfos != null) {
    print('Succeed! But failed to send a message to some friends: \n${result.failureInfos}');
  }
  } catch (error) {
  print('Failed to send a message. $error');
  }
}

Example: Using custom template

// Sending friends a message by scrapping a web page with a custom template

// Retrieving a list of friends.
Friends friends;
try {
  friends = await TalkApi.instance.friends();
} catch (error) {
  print('Failed to retrieve a list of friends. $error');
  return;
}

if (friends.elements == null) {
  return;
}

if (friends.elements!.isEmpty) {
  print('There is no friend to send a message to :(');
} else {
  // Retrieve UUIDs of the friends to send a message according to your service's environment.
  // This sample displays the Friends list and collects the UUIDs of the friends selected by a user.
  List<String> selectedItems = await Navigator.of(context).push(
  MaterialPageRoute(
      builder: (context) => FriendPage(
      items: friends.elements!
        .map((friend) => PickerItem(
          friend.uuid,
          friend.profileNickname ?? '',
          friend.profileThumbnailImage))
        .toList(),
        ),
    ),
    );

  if (selectedItems.isEmpty) {
  return;
  }
  print('Selected friends:\n${selectedItems.join('\n')}');

  // List of UUIDs of recipients to send a message to
  List<String> receiverUuids = selectedItems;

  // Web page URL to be shared
  //  * Caution: The domain of the URL to be shared must be registered in [My Appliction] > [Platform] > [Web] in Kakao Developers.
  String url = "https://developers.kakao.com";

  //  Message template ID
  // * Refer to the guide: https://developers.kakao.com/docs/latest/en/message-template/custom
  int templateId = templateIds['customMessage']!;

  // Sending friends a message by scrapping a web page with a custom template
  try {
  MessageSendResult result = await TalkApi.instance.sendScrapMessage(
      receiverUuids: receiverUuids,
      url: url,
  );
  print('Succeeded in sending a message to ${result.successfulReceiverUuids}.');

  if (result.failureInfos != null) {
      print('Succeed! But failed to send a message to some friends: \n${result.failureInfos}');
  }
  } catch (error) {
  print('Failed to send a message. $error');
  }
}

Upload image

You can attach images to a message by passing an image URL when configuring a message template or by uploading images in the Message template builder in advance. Images saved on local devices must be uploaded to the Kakao server or scraped to be used for message transmission. For detailed guidance and examples, see Upload image.

See more