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').
Before using Kakao Talk messaging APIs with the Flutter SDK,
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.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.
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 APIThere 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.
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.
Note that the Kakao Talk messaging APIs are categorized according to the message targets:
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.
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() |
Scrap | Default template | Me (MyChatroom) | sendScrapMemo() |
Scrap | Default template | Friends | sendScrapMessage() |
Scrap | Custom template | Me (MyChatroom) | sendScrapMemo() |
Scrap | Custom template | Friends | sendScrapMessage() |
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.
Permission | Prerequisite | Kakao Login | User consent |
---|---|---|---|
- | Register platforms Activate Kakao Login Manage consent items |
Required | Required: Send message in KakaoTalk |
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.
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 |
try {
await TalkApi.instance.sendDefaultMemo(defaultFeed);
print('Succeeded in sending me a message.');
} catch (error) {
print('Failed to send me a message. $error');
}
Permission | Prerequisite | Kakao Login | User consent |
---|---|---|---|
Required: API |
Register platforms Activate Kakao Login Manage consent items |
Required | Required: Send message in KakaoTalk |
sendDefaultMessage()
allows sending a message to up to five recipients at once. To send a Kakao Talk message to the user's friends,
uuid
s of message recipients.sendDefaultMessage()
method in the TalkApi
class by passing receiverUuids
and template
.Name | Type | Description | Required |
---|---|---|---|
receiverUuids | List<String> |
List of message recipients. Pass uuid obtained through the Retrieving list of friends API. Up to five uuid s 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 |
// 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.
Name | Type | Description | Required |
---|---|---|---|
successfulReceiverUuids | List<String> |
List of uuid s 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 |
Name | Type | Description | Required |
---|---|---|---|
code | Int |
Error code. | O |
msg | String |
Error message. | O |
receiverUuids | List<String> |
List that contains uuid s that are failed to receive a message. |
O |
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.
Permission | Prerequisite | Kakao Login | User consent |
---|---|---|---|
- | Register platforms Activate Kakao Login Manage consent items Message Template |
Required | Required: Send message in KakaoTalk |
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.
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 |
// 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');
}
Permission | Prerequisite | Kakao Login | User consent |
---|---|---|---|
Required: API |
Register platforms Activate Kakao Login Manage consent items Message Template |
Required | Required: Send message in KakaoTalk |
sendCustomMessage()
allows sending a message to up to five recipients at once. To send a Kakao Talk message to the user's friends,
uuid
s of message recipients.sendCustomMessage()
method in the TalkApi
class by passing receiverUuids
and templateId
as arguments.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 |
// 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.
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.
Permission | Prerequisite | Kakao Login | User consent |
---|---|---|---|
- | Register platforms Activate Kakao Login Manage consent items |
Required | Required: Send message in KakaoTalk |
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.
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 |
// 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');
}
Permission | Prerequisite | Kakao Login | User consent |
---|---|---|---|
Required: API |
Register platforms Activate Kakao Login Manage consent items |
Required | Required: Send message in KakaoTalk |
sendScrapMessage()
allows sending a message to up to five recipients at once. To send a Kakao Talk message to the user's friends,
uuid
s of message recipients.sendScrapMessage()
method in the TalkApi
class by passing receiverUuids
and url
as arguments.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 |
// 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 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 (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.
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.
Permission | Prerequisite | Kakao Login | User consent |
---|---|---|---|
- | Register platforms Activate Kakao Login Manage consent items Message Template |
Required | Required: Send message in KakaoTalk |
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.
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 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 scrap result. |
X |
// 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 (error) {
print('Failed to send me a message. $error');
}
Permission | Prerequisite | Kakao Login | User consent |
---|---|---|---|
Required: API |
Register platforms Activate Kakao Login Manage consent items Message Template |
Required | Required: Send message in KakaoTalk |
sendScrapMessage()
allows sending a message to up to five recipients at once. To send a Kakao Talk message to the user's friends,
uuid
s of message recipients.sendCustomMessage()
method in the TalkApi
class by passing receiverUuids
and url
as arguments.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 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 scrap result. |
X |
// 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.
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.