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

Message

Kakao Talk: Flutter

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

Before you begin

Before using Kakao Talk Messaging APIs with the Flutter SDK,

  1. Complete the prerequisite.
  2. Implement Kakao Login to call the token-based APIs. To obtain the tokens, a user also must be logged in with Kakao. For more information, refer to Concepts > Kakao Login.
  3. Add kakao_flutter_sdk_talk for Kakao Talk module and kakao_flutter_sdk_user for Kakao Login module in pubspec.yaml by referring to Install SDK. Afterthat, import the corresponding libraries in your dart file.
  4. Optional: To support a web app with the Flutter SDK, register a site domain used to send Kakao Talk messages and set Redirect URI used for Kakao Login.
    NOTE: Web app is supported in Flutter 1.3.0-beta.1 or higher.

Project Setting

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

Planning

According to your service's purpose and requirements, you need to decide which API to use first by considering their characteristics and difference.

1. Select a type of Messaging API

There are two types of messaging APIs: the Kakao Talk Sharing API and the Kakao Talk Messaging API. You need to understand the differences between the two messaging APIs completely by referring to Concepts, and decide which API to use to implement the function to send a message.

2. Select a message type and configuration method

Decide which message template to use by referring to Message template > Types.

You can configure a message as an object according to the default template or create a custom template in person for your service. Refer to How to use for more details.

3. Select a target

Note that the Kakao Talk Messaging APIs are categorized according to the message targets:

  • Send to me: Provides a feature to send a message to the currently logged-in user through Kakao Talk that is linked to the user's Kakao Account. This API is only allowed to send a message to the currently logged-in user, not to the user's friends.
  • Send to friends: Provides a feature to send a message to user's friends through Kakao Talk that is linked to the Kakao Account of the currently logged-in user. You need to implement a process to get information about the message recipients through the Retrieving a list of Kakao Talk friends API. Users can send a message to up to 5 friends at a time. The Kakao Talk Messaging API provides daily and monthly quotas. Refer to the quota.
Note

To send a Kakao Talk message to the user's friends, 1. Get permission. Before permission is granted to your app, you can only retrieve the list of the team members. 2. Enable the 'Send message in KakaoTalk' scope in [My Application] > [Kakao Login] > [Consent items]. A user must also consent to the scope. To see more about the conditions for providing friend information, refer to Usage policy.

APIs by conditions

According to the desired message type, the required components of the message and the method to call are different. Refer to Message template components and samples.

Message type Configuration method Target Method
Feed, List, Location, Commerce, Text, Calendar Default template Me (MyChatroom) sendDefaultMemo()
Feed, List, Location, Commerce, Text, Calendar Default template Friends sendDefaultMessage()
Feed, List, Commerce Custom template Me (MyChatroom) sendCustomMemo()
Feed, List, Commerce Custom template Friends sendCustomMessage()
Scrape Default template Me (MyChatroom) sendScrapMemo()
Scrape Default template Friends sendScrapMessage()
Scrape Custom template Me (MyChatroom) sendScrapMemo()
Scrape Custom template Friends sendScrapMessage()

Send message with default template

You can configure a message as an object type using a default template, and then allow users to send the message to the user's my chatroom or friends.

Send to me

Basic information
Permission Prerequisite Kakao Login User consent Reference
- Register platforms
Activate Kakao Login
Manage consent items
Required Required:
Send message in KakaoTalk
sendDefaultMemo()
FeedTemplate
ListTemplate
LocationTemplate
CommerceTemplate
TextTemplate
MessageSendResult
MessageFailureInfo

To send a Kakao Talk message to the user's My Chatroom using default templates, call the sendDefaultMemo() method in the TalkApi class. You must pass template as an argument when calling this method.

Parameter

Name Type Description Required
template FeedTemplate
ListTemplate
LocationTemplate
CommerceTemplate
TextTemplate
CalendarTemplate
Object of the message template to be sent.
For the desired template, you must create an instance by referring to Kakao Talk Sharing: Flutter > Configure a message.
O

Sample

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

Send to friends

Basic information
Permission Prerequisite Kakao Login User consent Reference
Required Register platforms
Activate Kakao Login
Manage consent items
Required Required:
Send message in KakaoTalk
sendDefaultMessage()
FeedTemplate
ListTemplate
LocationTemplate
CommerceTemplate
TextTemplate
MessageSendResult
MessageFailureInfo

sendDefaultMessage() allows sending a message to up to five recipients at once. To send a Kakao Talk message to the user's friends,

  1. Call the Retrieving list of friends API to obtain the uuids of message recipients.
  2. Call the sendDefaultMessage() method in the TalkApi class by passing receiverUuids and template.

Parameter

Name Type Description Required
receiverUuids List<String> List of message recipients.
Pass uuid ​​obtained through the Retrieving list of friends API.
Up to five uuids are allowed.
O
template FeedTemplate
ListTemplate
LocationTemplate
CommerceTemplate
TextTemplate
CalendarTemplate
Object of the message template to be sent.
For the desired template, you must create an instance by referring to Kakao Talk Sharing: Flutter > Configure a message.
O

Sample

// 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');
  }
}

Calling sendDefaultMessage() launches Kakao Talk or lets a user log in with Kakao Account on a web browser, and then shows a list of friends or chatrooms. When a user selects friends or a chatroom to send the message to, the messages are sent to the selected targets. If messages are successfully delivered, sendDefaultMessage() returns MessageSendResult. If failed, MessageFailureInfo containing the failure information is returned.

MessageSendResult
Name Type Description Required
successfulReceiverUuids List<String> List of uuids that a message is successfully sent to. X
failureInfos List<MessageFailureInfo> List that contains failure information.
Returned when you request to send a message to two or more (up to five) recipients but it fails to send some recipients.
If you request to send a message to a single recipient and it fails, only the error code and message are returned without failureInfos
X
MessageFailureInfo
Name Type Description Required
code Int Error code. O
msg String Error message. O
receiverUuids List<String> List that contains uuids that are failed to receive a message. O

Send message with custom template

Unlike the Sending message with default template, you can customize a message template in [Tools] > [Message Template Builder] to send a message. Refer to Message template builder.

To use a custom template, you must pass the template ID that you have registered in [Message Template Builder] through templateId as an argument. You can also use user arguments for some components when you want to add variable information to the custom template message. For this, pass key and value pairs through templateArgs. Otherwise, the defined argument is displayed to users as raw data, such as ${key}.

Depending on the target to send the message, the method to call is different.

Send to me

Basic information
Permission Prerequisite Kakao Login User consent Reference
- Register platforms
Activate Kakao Login
Manage consent items
Message Template
Required Required:
Send message in KakaoTalk
sendCustomMemo()
MessageSendResult
MessageFailureInfo

To send a Kakao Talk message to the user's My Chatroom using custom templates, call the sendCustomMemo() method in the TalkApi class. You must pass templateId when calling this method. If this method is called, the customized message is sent to a user's my chatroom on Kakao Talk.

Parameter

Name Type Description Required
templateId Int Template ID of the custom template registered in [Tools] > [Message Template Builder].

Note: To use a custom template for sending to me, set the purpose of the custom template as [Kakao Talk Sharing].
O
templateArgs Map<String, String> If the specified template contains a user argument, use this parameter to pass key-value pairs. X

Sample

// Sending me a message with a custom template

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

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 to friends

Basic information
Permission Prerequisite Kakao Login User consent Reference
Required Register platforms
Activate Kakao Login
Manage consent items
Message Template
Required Required:
Send message in KakaoTalk
sendCustomMessage()
MessageSendResult
MessageFailureInfo

sendCustomMessage() allows sending a message to up to five recipients at once. To send a Kakao Talk message to the user's friends,

  1. Call the Retrieving list of friends API to obtain the uuids of message recipients.
  2. Call the sendCustomMessage() method in the TalkApi class by passing receiverUuids and templateId as arguments.

Parameter

Name Type Description Required
receiverUuids List<String> uuid ​​obtained through the Retrieving list of friends API.
Up to five uuids are allowed.
O
templateId Int Template ID of the custom template registered in [Tools] > [Message Template Builder]. O
templateArgs Map<String, String> If the specified template contains a user arguments, use this parameter to pass key-value pairs. X

Sample

// 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;

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

  // Send a message.
  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');
  }
}

Calling sendCustomMessage() launches Kakao Talk or lets a user log in with Kakao Account on a web browser, and then shows a list of friends or chatrooms. When a user selects friends or a chatroom to send the message to, the messages are sent to the selected targets. If messages are successfully delivered, sendCustomMessage() returns MessageSendResult. If failed, MessageFailureInfo containing the failure information is returned.

Send scrape message with default template

You can send a message by scrapping a web page with a default template. This API scrapes a web page, and then configures a message based on the scraped web page information to send a message. Thus, when you request to send a scrape message, you must pass url, a web page to be scraped. Make sure that you have registered the domain of the web page to be scraped as a site domain in [My Application] > [Platform] > [Web] in advance.

Depending on the target to send the message, the method to call is different.

Send to me

Basic information
Permission Prerequisite Kakao Login User consent Reference
- Register platforms
Activate Kakao Login
Manage consent items
Required Required:
Send message in KakaoTalk
sendScrapMemo()
FeedTemplate
ListTemplate
LocationTemplate
CommerceTemplate
TextTemplate
MessageSendResult
MessageFailureInfo

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.

Parameter

Name Type Description Required
url String Web page URL to be scraped.
Its domain must match the domain registered on the Kakao Developers.
Refer to Scrape message.
O

Sample

// 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');
}

Send to friends

Basic information
Permission Prerequisite Kakao Login User consent Reference
Required Register platforms
Activate Kakao Login
Manage consent items
Required Required:
Send message in KakaoTalk
sendScrapMessage()
FeedTemplate
ListTemplate
LocationTemplate
CommerceTemplate
TextTemplate
MessageSendResult
MessageFailureInfo

sendScrapMessage() allows sending a message to up to five recipients at once. To send a Kakao Talk message to the user's friends,

  1. Call the Retrieving list of friends API to obtain the uuids of message recipients.
  2. Call the sendScrapMessage() method in the TalkApi class by passing receiverUuids and url as arguments.

Parameter

Name Type Description Required
receiverUuids List<String> uuid ​​obtained through the Retrieving list of friends API.
Up to five uuids are allowed.
O
url String Web page URL to be scraped.
Its domain must match the domain registered on the Kakao Developers.
Refer to Scrape message.
O

Sample

// 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');
  }
}

Calling sendScrapMessage() launches Kakao Talk or lets a user log in with Kakao Account on a web browser, and then shows a list of friends or chatrooms. When a user selects friends or a chatroom to send the message to, the messages are sent to the selected targets. If messages are successfully delivered, sendScrapMessage() returns MessageSendResult. If failed, MessageFailureInfo containing the failure information is returned.

Send scrape message with custom template

You can configure a message with a custom template by scraping a web page, and then send it through Kakao Talk. You can use a custom template registered in [Tools] > [Message Template Builder] when requesting to send a scrape message. Refer to Message template builder.

For a scrape message, you must pass url, a web page to be scraped. Make sure that you have registered the domain of the web page to be scraped as a site domain in [My Application] > [Platform] > [Web] in advance.

Depending on the target to send the message, the method to call is different.

Send to me

Basic information
Permission Prerequisite Kakao Login User consent Reference
- Register platforms
Activate Kakao Login
Manage consent items
Message Template
Required Required:
Send message in KakaoTalk
sendScrapMemo()
MessageSendResult
MessageFailureInfo

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

If this method is called, the scraped message is sent to a user's my chatroom on Kakao Talk.

Parameter

Name Type Description Required
url String Web page URL to be scraped.
Its domain must match the domain registered on the Kakao Developers.
O
templateId Int Used when you want to send a scrape message with the template registered in [Tools] > [Message Template Builder].
Specify the ID of the template to apply.
When you use this parameter, the scraped content is applied in the template with the specified templateId.

Note: To use a custom template for sending to me, set the purpose of the custom template as [Kakao Talk Sharing].
O
templateArgs Map<String, String> If you specify templateId and the specified template contains other user arguments besides the default argument keys, pass the user arguments using this parameter in key:value format.
You cannot overwrite the scrape result.
X

Sample

// Sending me a scrape message with a custom 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';

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

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 to friends

Basic information
Permission Prerequisite Kakao Login User consent Reference
Required Register platforms
Activate Kakao Login
Manage consent items
Message Template
Required Required:
Send message in KakaoTalk
sendScrapMessage()
MessageSendResult
MessageFailureInfo

sendScrapMessage() allows sending a message to up to five recipients at once. To send a Kakao Talk message to the user's friends,

  1. Call the Retrieving list of friends API to obtain the uuids of message recipients.
  2. Call the sendCustomMessage() method in the TalkApi class by passing receiverUuids and url as arguments.

Parameter

Name Type Description Required
receiverUuids List<String> uuid ​​obtained through the Retrieving list of friends API.
Up to five uuids are allowed.
O
url String Web page URL to be scraped.
Its domain must match the domain registered on the Kakao Developers.
O
templateId Int Used when you want to send a scrape message with the template registered in [Tools] > [Message Template Builder].
Specify the ID of the template to apply.
When you use this parameter, the scraped content is applied in the template with the specified templateId.
O
templateArgs Map<String, String> If you specify templateId and the specified template contains other user arguments besides the default argument keys, pass the user arguments using this parameter in key:value format.
You cannot overwrite the scrape result.
X

Sample

// 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/message-templatee/message-template
  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');
  }
}

Calling sendCustomMessage() launches Kakao Talk or lets a user log in with Kakao Account on a web browser, and then shows a list of friends or chatrooms. When a user selects friends or a chatroom to send the message to, the messages are sent to the selected targets. If messages are successfully delivered, sendCustomMessage() returns MessageSendResult. If failed, MessageFailureInfo containing the failure information is returned.

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.

If it is difficult to obtain the image file URL, you can either upload an image file to the Kakao server or scrape it. You can only upload an image with a file size of 5 MB or less. The images uploaded to the Kakao server are stored for up to 100 days and automatically deleted after the period. Refer to Kakao Talk Sharing: Flutter > Upload image.

See more