페이지 이동경로
  • 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 (hereinafter referred to as 'Flutter SDK').

Tag used in this document

Tag Description
Login required The API marked with this tag requires Kakao Login. You must implement the Kakao Login function first, and then call the corresponding API by using the access token issued when a user logs in.
Consent required To use the API marked with this tag, you must enable the 'Send message in KakaoTalk' scope.
In addition, a user must also consent to the scope. Otherwise, an error occurs.

Before you begin

Before using Kakao Talk messaging APIs with the Flutter SDK, you must complete the prerequisites.

Add modules

To use the features of Kakao Talk messaging service, you need to 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. After that, add the following libraries in your dart file.

import 'package:kakao_flutter_sdk_user/kakao_flutter_sdk_user.dart'; // Kakao Login required
import 'package:kakao_flutter_sdk_talk/kakao_flutter_sdk_talk.dart';

Choose an API to use

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

Step 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 Understand concepts, and decide which API to use to implement the function to send a message.

Step 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 Message configuration method for more details.

Step 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 Operating policy.
IMPORTANT

To send a Kakao Talk message to the user's friends, 1. Get permission. Before permission is granted to your app, you can call this API only for 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 Default template Me (MyChatroom) sendDefaultMemo()
Feed, List, Location, Commerce, Text Default template Friends sendDefaultMessage()
Feed, List, Commerce Custom template Me (MyChatroom) sendCustomMemo()
Feed, List, Commerce Custom template Friends sendCustomMessage()
Scrap Default template Me (MyChatroom) sendScrapMemo()
Scrap Default template Friends sendScrapMessage()
Scrap Custom template Me (MyChatroom) sendScrapMemo()
Scrap Custom template Friends sendScrapMessage()

Set Custom URL Scheme

To make your app launch when a user clicks a button in the Kakao Talk message, you must set a custom URL scheme.

Send message with default template Login required Consent required

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

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
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 and Message template components.
O
Sample
try {
  await TalkApi.instance.sendDefaultMemo(defaultFeed);
  print('Succeeded in sending me a message.');
} catch (e) {
  print('Failed to send me a message.');
}

Send to friends

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
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 and Message template components.
O
Sample
// Retrieve a list of Kakao Talk friends.
Friends friends;
try {
  friends = await TalkApi.instance.friends();
} catch (e) {
  print('Failed to retrieve a list of friends.');
  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 (e) {
  print('Failed to send a message.');
  }
}
Return data

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 Login required Consent required

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

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]. 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 (e) {
  print('Failed to send me a message.');
}

Send to friends

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 (e) {
  print('Failed to retrieve a list of friends.');
  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 (e) {
  print('Failed to send a message.');
  }
}
Return data

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 scrap message with default template Login required Consent required

You can send a message by scrapping a web page with a default template. This API scraps 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 scrap 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

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 Scrap 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 (e) {
  print('Failed to send me a message. $e');
}

Send to friends

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 Scrap 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 (e) {
  print('Failed to retrieve a list of friends.');
  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 scrap 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 (e) {
  print('Failed to send a message.');
  }
}
Return data

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 scrap message with custom template Login required Consent required

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 scrap message. Refer to Message template builder.

For a scrap 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

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 scrapped 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 scrap 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 specifed 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 scrap result.
X
Sample
// Sending me a scrap 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 (e) {
  print('Failed to send me a message.');
}

Send to friends

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 scrap 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 specifed 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 scrap 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 (e) {
  print('Failed to retrieve a list of friends.');
  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 (e) {
  print('Failed to send a message.');
  }
}
Return data

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.

To use the image file stored on your device for a message, you can either upload or scrape an image file to the Kakao Talk sharing server, and then obtain its URL value. Refer to Kakao Talk sharing: Flutter > Upload image.

See more