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

Kakao Talk Message

iOS

This document describes how to integrate the Kakao Talk Message API into your service with the Kakao SDK for iOS ("iOS 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.


Set Custom URL Scheme

Kakao Talk messages include links that execute specified web pages or apps. Buttons in messages execute apps using Custom URL Scheme (Custom URL Scheme) composed of URI schemes and parameters.

To allow users to execute your app using buttons in Kakao Talk messages, refer to Configuration to configure app execution allowlist and URL scheme settings. For detailed setup instructions, see Custom URL scheme configuration.

Send me message with default template

Basic information
Reference App setting
[SDK, RxSDK] sendDefaultMemo()
[SDK] MessageSendResult
[SDK] MessageFailureInfo
Install
Import modules
Initialize
Set Custom URL Scheme
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 templatable 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

Swift
RxSwift
// For 'templatable', refer to the 'Configure a message' guide.
if let templatable = try? SdkJSONDecoder.custom.decode(FeedTemplate.self, from: feedTemplateJsonStringData) {
    TalkApi.shared.sendDefaultMemo(templatable: templatable) {(error) in
        if let error = error {
            print(error)
        }
        else {
            print("success.")
        }
    }
}
// Class member property
let disposeBag = DisposeBag()

// For 'templatable', refer to the 'Configure a message' guide.
if let templatable = try? SdkJSONDecoder.custom.decode(FeedTemplate.self, from: feedTemplateJsonStringData) {
    TalkApi.shared.rx.sendDefaultMemo(templatable:templatable)
        .retry(when: Auth.shared.rx.incrementalAuthorizationRequired())
        .subscribe (onCompleted:{
            print("success.")            
        }, onError: {error in
            print(error)
        })
        .disposed(by: disposeBag)
}

Send me message with custom template

Basic information
Reference App setting
[SDK, RxSDK] sendCustomMemo()
[SDK] MessageSendResult
[SDK] MessageFailureInfo
Install
Import modules
Initialize
Set Custom URL Scheme
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

Swift
RxSwift
let templateId : Int64 = 12345

TalkApi.shared.sendCustomMemo(templateId: templateId, templateArgs: ["msg":"메세지 파라미터"]) {(error) in
    if let error = error {
        print(error)
    }
    else {
        print("success.")
    }
}
// Class member property
let disposeBag = DisposeBag()

let templateId : Int64 = 12345

TalkApi.shared.rx.sendCustomMemo(templateId: templateId, templateArgs: ["msg":"메세지 파라미터"])
    .retry(when: Auth.shared.rx.incrementalAuthorizationRequired())
    .subscribe (onCompleted:{
        print("success.")        
    }, onError: {error in
        print(error)
    })
    .disposed(by: disposeBag)

Send me scrape message

Basic information
Reference App setting
[SDK, RxSDK] sendScrapMemo()
[SDK] MessageSendResult
[SDK] MessageFailureInfo
Install
Import modules
Initialize
Set Custom URL Scheme
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

You must pass the URL of the web page to be scraped as the requestUrl parameter. The domain of the web page to be scraped must be registered in [App] > [General] > [Platform] > [Web] on the app management page.

If you want to send a scrape message based on a message template defined by your service, you must pass the ID of the template 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. For detailed usage, see User arguments.

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

Swift
RxSwift
let requestUrl = "https://developers.kakao.com"

TalkApi.shared.sendScrapMemo(requestUrl: requestUrl) {(error) in
    if let error = error {
        print(error)
    }
    else {
        print("success.")
    }
}
// Class member property
let disposeBag = DisposeBag()

let requestUrl = "https://developers.kakao.com"

TalkApi.shared.rx.sendScrapMemo(requestUrl: requestUrl)
    .retry(when: Auth.shared.rx.incrementalAuthorizationRequired())
    .subscribe (onCompleted:{        
        print("success.")        
    }, onError: {error in
        print(error)
    })
    .disposed(by: disposeBag)

Example: Using custom template

Swift
RxSwift
let requestUrl = "https://developers.kakao.com"
let templateId : Int64 = 12345

TalkApi.shared.sendScrapMemo(requestUrl: requestUrl, templateId: templateId, templateArgs:["title":"This is title.", "description":"This is description."]) {(error) in
    if let error = error {
        print(error)
    }
    else {
        print("success.")
    }
}
// Class member property
let disposeBag = DisposeBag()

let requestUrl = "https://developers.kakao.com"
let templateId : Int64 = 12345

TalkApi.shared.rx.sendScrapMemo(requestUrl: requestUrl, templateId: templateId, templateArgs:["title":"This is title.", "description":"This is description."])
    .retry(when: Auth.shared.rx.incrementalAuthorizationRequired())
    .subscribe (onCompleted:{        
        print("success.")        
    }, onError: {error in
        print(error)
    })
    .disposed(by: disposeBag)

Send friends message with default template

Basic information
Reference App setting
[SDK, RxSDK] sendDefaultMessage()
[SDK] MessageSendResult
[SDK] MessageFailureInfo
Install
Import modules
Initialize
Set Custom URL Scheme
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 templatable 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

Swift
RxSwift
// For 'templatable', refer to the 'Configure a message' guide.
if let templatable = try? SdkJSONDecoder.custom.decode(FeedTemplate.self, from: feedTemplateJsonStringData) {
    // Retrieve a list of friends.
    TalkApi.shared.friends {(friends, error) in
        if let error = error {
            print(error)
        } else {
            print("friends() success.")
            guard let friends = friends else {
                print(error)
                return
            }
            
            //Implement a window to select friends.
            ...
        
            //uuids of the friends selected in the window. 
            let friendUuids = selectedIds as! [String]
                    
            // Send a Kakao Talk message.
            TalkApi.shared.sendDefaultMessage(templatable: templatable, receiverUuids: friendUuids) { (messageSendResult, error) in
                if let error = error {
                    print(error)
                } else {
                    print("sendDefaultMessage() success.")
                    
                    //Do something
                    _ = messageSendResult
                }
            }
        }
    }
}
// Class member property
let disposeBag = DisposeBag()

// For 'templatable', refer to the 'Configure a message' guide.
if let templatable = try? SdkJSONDecoder.custom.decode(FeedTemplate.self, from: feedTemplateJsonStringData) {
    // Retrieve a list of friends.
    TalkApi.shared.rx.friends()
        .retry(when: Auth.shared.rx.incrementalAuthorizationRequired())
        .subscribe(onSuccess: { (friends) in
            print("friends() success.")
            
            //Implement a window to select friends.
            ...
        
            //uuids of the friends selected in the window. 
            let friendUuids = selectedIds as! [String]

            // Send a Kakao Talk message.
            TalkApi.shared.rx.sendDefaultMessage(templatable:templatable, receiverUuids:friendUuids)
            .retry(when: Auth.shared.rx.incrementalAuthorizationRequired())
            .subscribe(onSuccess:{ (messageSendResult) in
                print("sendDefaultMessage() success.")
                //Do something
                _ = messageSendResult

            }, onFailure: {error in
                print(error)
            })
            .disposed(by: disposeBag)
            
        }, onFailure: {error in
            print(error)
        })
        .disposed(by: disposeBag)
}

Send friends message with custom template

Basic information
Reference App setting
[SDK, RxSDK] sendCustomMessage()
[SDK] MessageSendResult
[SDK] MessageFailureInfo
Install
Import modules
Initialize
Set Custom URL Scheme
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.

Example

Swift
RxSwift
let templateId : Int64 = 12345

// Retrieve a list of friends.
TalkApi.shared.friends {(friends, error) in
    if let error = error {
        print(error)
    } else {
        print("friends() success.")
        guard let friends = friends else {
            print(error)
            return
        }
        
        //Implement a window to select friends.
        ...
        
        //uuids of the friends selected in the window. 
        let friendUuids = selectedIds as! [String]

        // Send a Kakao Talk message.
        TalkApi.shared.sendCustomMessage(templateId:templateId, templateArgs:["title":"This is title.", "description":"This is description."], receiverUuids:friendUuids) { (messageSendResult, error) in
            if let error = error {
                print(error)
            } else {
                print("sendCustomMessage() success.")

                //Do something
                _ = messageSendResult
            }
        }   
    }
}
// Class member property
let disposeBag = DisposeBag()

let templateId : Int64 = 12345

// Retrieve a list of friends.
TalkApi.shared.rx.friends()
    .retry(when: Auth.shared.rx.incrementalAuthorizationRequired())
    .subscribe(onSuccess: { (friends) in
        print("friends() success.")
        
        //Implement a window to select friends.
        ...
        
        //uuids of the friends selected in the window. 
        let friendUuids = selectedIds as! [String]

        // Send a Kakao Talk message.
        TalkApi.shared.rx.sendCustomMessage(templateId:templateId, templateArgs:["title":"This is title.", "description":"This is description."], receiverUuids:friendUuids)
            .retry(when: Auth.shared.rx.incrementalAuthorizationRequired())
            .subscribe(onSuccess:{ (messageSendResult) in
                print("sendCustomMessage() success.")
                
                //Do something
                _ = messageSendResult

            }, onFailure: {error in
                print(error)
            })
            .disposed(by: disposeBag)                
            
    }, onFailure: {error in
        print(error)
    })
    .disposed(by: disposeBag)

Send friends scrape message

Basic information
Reference App setting
[SDK, RxSDK] sendScrapMessage()
[SDK] MessageSendResult
[SDK] MessageFailureInfo
Install
Import modules
Initialize
Set Custom URL Scheme
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 the currently logged-in user's Kakao Talk.

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.
  2. Specify web page URL for scraping: When calling sendScrapMessage(), you must pass the URL of the web page to be scraped as the requestUrl parameter. The domain of the web page to be scraped must be registered in [App] > [General] > [Platform] > [Web] on the app management page.
  3. Apply custom template (optional): If you want to send a scrape message based on a message template defined by your service, you must pass the ID of the template 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 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: Using default template

Swift
RxSwift
let requestUrl = "https://developers.kakao.com"

// Retrieve a list of friends.
TalkApi.shared.friends {(friends, error) in
    if let error = error {
        print(error)
    } else {
        print("friends() success.")
        guard let friends = friends else {
            print(error)
            return
        }
        
        //Implement a window to select friends.
        ...
        
        //uuids of the friends selected in the window. 
        let friendUuids = selectedIds as! [String]

        // Send a scrape message.
        TalkApi.shared.sendScrapMessage(requestUrl:requestUrl, receiverUuids:friendUuids) { (messageSendResult, error) in
            if let error = error {
                print(error)
            }
            else {
                print("sendScrapMessage() success.")
                //Do something
                _ = messageSendResult
            }
        }
    }
}
// Class member property
let disposeBag = DisposeBag()

let requestUrl = "https://developers.kakao.com"

// Retrieve a list of friends.
TalkApi.shared.rx.friends()
    .retry(when: Auth.shared.rx.incrementalAuthorizationRequired())
    .subscribe(onSuccess: { (friends) in
        print("friends() success.")

        //Implement a window to select friends.
        ...
        
        //uuids of the friends selected in the window. 
        let friendUuids = selectedIds as! [String]

        TalkApi.shared.rx.sendScrapMessage(requestUrl:requestUrl, receiverUuids:friendUuids)
            .retry(when: Auth.shared.rx.incrementalAuthorizationRequired())
            .subscribe(onSuccess:{ (messageSendResult) in
                print("sendScrapMessage() success.")
                
                //Do something
                _ = messageSendResult
                
            }, onFailure: {error in
                print(error)
            })
            .disposed(by: disposeBag)
        
    }, onFailure: {error in
        print(error)
    })
    .disposed(by: disposeBag)

Example: Using custom template

Swift
RxSwift
let requestUrl = "https://developers.kakao.com"
let templateId : Int64 = 12345

// Retrieve a list of friends.
TalkApi.shared.friends {(friends, error) in
    if let error = error {
        print(error)
    } else {
        print("friends() success.")
        guard let friends = friends else {
            print(error)
            return
        }
        
        //Implement a window to select friends.
        ...
        
        //uuids of the friends selected in the window. 
        let friendUuids = selectedIds as! [String]

        // Send a Kakao Talk message.
        TalkApi.shared.sendScrapMessage(requestUrl:requestUrl, templateId:templateId, receiverUuids:friendUuids) { (messageSendResult, error) in
            if let error = error {
                print(error)
            }
            else {
                print("sendScrapMessage() success.")
                //Do something
                _ = messageSendResult
            }
        }
    }
}
// Class member property
let disposeBag = DisposeBag()

let requestUrl = "https://developers.kakao.com"
let templateId : Int64 = 12345

TalkApi.shared.rx.friends()
    .retry(when: Auth.shared.rx.incrementalAuthorizationRequired())
    .subscribe(onSuccess: { (friends) in
        print("friends() success.")

        //Implement a window to select friends.
        ...
        
        //uuids of the friends selected in the window. 
        let friendUuids = selectedIds as! [String]

        TalkApi.shared.rx.sendScrapMessage(requestUrl:requestUrl, templateId:templateId, receiverUuids:friendUuids)
            .retry(when: Auth.shared.rx.incrementalAuthorizationRequired())
            .subscribe(onSuccess:{ (messageSendResult) in
                print("sendScrapMessage() success.")
                
                //Do something
                _ = messageSendResult
                
            }, onFailure: {error in
                print(error)
            })
            .disposed(by: disposeBag)
        
    }, onFailure: {error in
        print(error)
    })
    .disposed(by: disposeBag)

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. Refer to Upload image.

See more