This document describes how to integrate Kakao Talk Messaging APIs into your service with the Kakao SDK for Flutter ("Flutter SDK").
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.
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 How to use 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() |
Scrape | Default template | Me (MyChatroom) | sendScrapMemo() |
Scrape | Default template | Friends | sendScrapMessage() |
Scrape | Custom template | Me (MyChatroom) | sendScrapMemo() |
Scrape | Custom template | Friends | sendScrapMessage() |
Reference | App setting |
---|---|
sendDefaultMemo() sendDefaultMessage() 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 KakaoTalk |
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.
If messages are successfully delivered, sendDefaultMessage()
returns MessageSendResult
. If failed, MessageFailureInfo
containing the failure information is returned.
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.
try {
await TalkApi.instance.sendDefaultMemo(defaultFeed);
print('Succeeded in sending me a message.');
} catch (error) {
print('Failed to send me a message. $error');
}
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
.// 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');
}
}
Reference | App setting |
---|---|
sendCustomMemo() sendCustomMessage() 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 KakaoTalk |
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.
If messages are successfully delivered, sendCustomMessage()
returns MessageSendResult
. If failed, MessageFailureInfo
containing the failure information is returned.
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.
// 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');
}
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.// 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');
}
}
Reference | App setting |
---|---|
sendScrapMemo() sendScrapMessage() 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 KakaoTalk |
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.
If messages are successfully delivered, sendScrapMessage()
returns MessageSendResult
. If failed, MessageFailureInfo
containing the failure information is returned.
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.
// 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');
}
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.// 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');
}
}
Reference | App setting |
---|---|
sendScrapMemo() sendScrapMessage() 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 KakaoTalk |
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.
If messages are successfully delivered, sendCustomMessage()
returns MessageSendResult
. If failed, MessageFailureInfo
containing the failure information is returned.
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.
// 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');
}
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.// 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');
}
}
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. Refer to Upload image.