Agent kakaotalk

From agent-messenger/agent-messenger · View interactive version

Agent kakaotalk is an AI agent skill from the GitHub repository agent-messenger/agent-messenger. Interact with KakaoTalk - send messages, read chats, manage conversations

How to use this skill

Skill file

Agent KakaoTalk

A TypeScript CLI tool that enables AI agents and humans to interact with KakaoTalk through a simple command interface. Features sub-device login that keeps your desktop app running.

Key Concepts

Before diving in, a few things about KakaoTalk's architecture:

Quick Start

# Login (registers as sub-device, desktop app stays running)
agent-kakaotalk auth login

# List chat rooms
agent-kakaotalk chat list

# Send a message
agent-kakaotalk message send <chat-id> "Hello from AI agent!"

# List messages in a chat
agent-kakaotalk message list <chat-id>

# Show your identity
agent-kakaotalk whoami

Authentication

Registers the CLI as a sub-device (tablet slot by default). Your desktop app keeps running.

agent-kakaotalk auth login

In interactive mode, this prompts for email and password. On macOS and Windows, the CLI first tries to extract cached credentials from the desktop app so you may not need to type anything. On Linux there is no desktop app, so always pass credentials explicitly via --email and --password (or --password-file).

For AI agents (non-interactive), provide credentials via flags:

agent-kakaotalk auth login --email user@example.com --password mypass

Device registration flow: On first login, KakaoTalk requires device verification:

  1. The CLI requests a passcode from KakaoTalk's server
  2. A numeric code is displayed — enter it on your phone when prompted
  3. The CLI polls until you confirm on your phone
  4. Login completes automatically after confirmation

IMPORTANT: NEVER guide the user to open a web browser, use DevTools, or manually copy tokens. Always use agent-kakaotalk auth login.

Agent Behavior (MANDATORY)

When a command fails because no account is configured, the agent MUST drive the auth flow itself:

Step 1: Check auth status

agent-kakaotalk auth status

If authenticated → retry the original command.

Step 2: Login (registers as sub-device — desktop app stays running)

agent-kakaotalk auth login

The CLI auto-extracts the email (and password if available) from the desktop app. On fresh installs, the CLI may prompt for the KakaoTalk password once (one-time device registration). After registration, the password is never needed again.

Possible responses:

Alternatively, use --password-file:

agent-kakaotalk auth login --password-file /tmp/.kakao-pw

The --password-file flag reads the password from the file and deletes the file immediately after reading. The password never appears in chat, shell history, or process list.

Step 3: Retry the original command

After successful auth, immediately execute whatever the user originally asked for.

Device Slots

KakaoTalk allows these simultaneous sessions:

# Default: tablet slot (safe for most users)
agent-kakaotalk auth login

# Use PC slot instead (kicks desktop app)
agent-kakaotalk auth login --device-type pc

# Force login even if slot is occupied
agent-kakaotalk auth login --device-type tablet --force

Multi-Account

KakaoTalk supports multiple accounts. Each login stores credentials separately, keyed by user ID.

Listing Accounts

agent-kakaotalk auth list
agent-kakaotalk auth list --pretty

Switching Accounts

agent-kakaotalk auth use <account-id>

Using a Specific Account

All data commands accept --account <id> to use a specific account without switching the default:

agent-kakaotalk chat list --account 1234567890
agent-kakaotalk message list <chat-id> --account 1234567890
agent-kakaotalk message send <chat-id> "Hello" --account 1234567890

Without --account, commands use the current (default) account.

Memory

The agent maintains a ~/.config/agent-messenger/MEMORY.md file as persistent memory across sessions. This is agent-managed — the CLI does not read or write this file. Use the Read and Write tools to manage your memory file.

Reading Memory

At the start of every task, read ~/.config/agent-messenger/MEMORY.md using the Read tool to load any previously discovered chat IDs, friend names, and preferences.

Writing Memory

After discovering useful information, update ~/.config/agent-messenger/MEMORY.md using the Write tool. Write triggers include:

When writing, include the complete file content — the Write tool overwrites the entire file.

What to Store

What NOT to Store

Never store tokens, passwords, credentials, or any sensitive data. Never store full message content (just IDs and chat context). Never store OAuth tokens or device UUIDs.

Handling Stale Data

If a memorized chat ID returns an error, remove it from MEMORY.md. Don't blindly trust memorized data — verify when something seems off. Prefer re-listing over using a memorized ID that might be stale.

Format / Example

# Agent Messenger Memory

## KakaoTalk Account

- User ID: `1234567890`
- Device type: tablet

## Chat Rooms

- `9876543210` — Work group chat (Alice, Bob, Charlie)
- `1111111111` — 1:1 with Alice
- `2222222222` — Family group

## Aliases

- "work" → `9876543210` (Work group chat)
- "alice" → `1111111111` (1:1 with Alice)

## Notes

- User prefers --pretty output
- Work chat is the most frequently used

Memory lets you skip repeated chat list calls. When you already know a chat ID from a previous session, use it directly.

Commands

Auth Commands

# Login as sub-device (recommended)
agent-kakaotalk auth login
agent-kakaotalk auth login --email <email> --password <password>
agent-kakaotalk auth login --device-type pc --force
agent-kakaotalk auth login --debug

# Check auth status
agent-kakaotalk auth status

# Remove stored credentials
agent-kakaotalk auth logout
agent-kakaotalk auth logout --account <account-id>

# List all stored accounts
agent-kakaotalk auth list
agent-kakaotalk auth list --pretty

# Switch the current account
agent-kakaotalk auth use <account-id>

# Check status of specific account
agent-kakaotalk auth status --account <account-id>

# Remove specific account
agent-kakaotalk auth logout --account <account-id>

Whoami Command

# Show current authenticated user
agent-kakaotalk whoami
agent-kakaotalk whoami --pretty
agent-kakaotalk whoami --account <account-id>

Output includes:

Chat Commands

# List all chat rooms (sorted by most recent activity)
agent-kakaotalk chat list
agent-kakaotalk chat list --pretty
agent-kakaotalk chat list --account <account-id>
agent-kakaotalk chat list --account <account-id> --pretty

# Resolve user-set room titles via CHATINFO (one extra LOCO call per chat;
# slower, but matches the room name shown in the official KakaoTalk app)
agent-kakaotalk chat list --resolve-titles

Output includes:

Chat Leave

# Leave a chat room (works on 1:1, group, open, and PlusChat rooms)
agent-kakaotalk chat leave <chat-id>
agent-kakaotalk chat leave <chat-id> --pretty
agent-kakaotalk chat leave <chat-id> --account <account-id>

Output (JSON by default; --pretty pretty-prints the same JSON):

{ "success": true, "status_code": 0, "chat_id": "9876543210" }

The process exits non-zero when success is false.

Member Commands

# List all members of a chat room (read-only: CHATINFO + GETMEM, each read twice)
agent-kakaotalk member list <chat-id>
agent-kakaotalk member list <chat-id> --pretty
agent-kakaotalk member list <chat-id> --account <account-id>

# Return what could be read even if it is not confirmed complete
agent-kakaotalk member list <chat-id> --allow-partial

# Opt in to entering the room (CHATONROOM) when the read-only list is incomplete
agent-kakaotalk member list <chat-id> --allow-room-entry
agent-kakaotalk member list <chat-id> --allow-room-entry --allow-partial

By default member list fails (non-zero exit, error on stderr) unless the

member records match the chat's active member count and stay stable across

both reads. In some large open chats GETMEM returns fewer records than the

active member count, and members may also join or leave while the list is

read; either way the default command fails rather than returning an

incomplete list.

returns it even when it is incomplete:

```json

{

"chat_id": "9876543210",

"active_members": 1414,

"members": [{ "user_id": "1234567890", "nickname": "Alice", "...": "..." }],

"complete": false,

"consistency_basis": "stable_double_read_chatinfo_getmem",

"incomplete_reason": "member_count_mismatch"

}

```

incomplete_reason is member_count_mismatch (reads were stable but the

returned member set or count does not match the active roster, e.g. a

displayed member ID is missing) or membership_changed (the reads

disagreed, e.g. someone joined or left). It is absent when complete is

true. Always check complete before treating the list as the full roster.

room's member id list (CHATONROOM), resolving ids GETMEM did not return

with MEMBER (100 ids per request). Output stays a bare array unless

--allow-partial is also given; consistency_basis is then

chatonroom_ids_member_batch. Side effect: CHATONROOM is the

room-entry command and can advance this account's unread state for the

chat (the chat may show as read). It is only sent when the read-only list

is incomplete.

Agent rule: Do not pass --allow-room-entry unless the user accepts that

the chat may be marked as read. Use --allow-partial when a best-effort

roster is enough, and never treat a complete: false result as the full

member list (for example, to decide that someone is not in the chat).

Each member includes:

SDK-only: KakaoTalkClient.getMembersByIds(chatId, userIds) is available for the >100-member case where you already have specific user IDs to resolve (typically from a CHATONROOM mi array). It is not exposed as its own CLI command; member list --allow-room-entry uses it internally. Use agent-kakaotalk member list for the common case.

Open Chat Moderation (Kick)

Open chats (오픈채팅) only. The account must be the room's host or a co-host. The open chat link ID is resolved from the chat ID automatically; regular chats fail with Chat <chat-id> is not an open chat before any moderation packet is sent. Only member kick (KICKMEM) has been used against a live server; the member kick-list (KLSYNC) and member unkick (KLDELITEM) request shapes and the kick-list response fields are unverified.

# Preview only: without --force, prints a warning and exits 1 without connecting
agent-kakaotalk member kick <chat-id> <user-id>

# Kick a member (IRREVERSIBLE — also blocks them from rejoining via the link)
agent-kakaotalk member kick <chat-id> <user-id> --force
agent-kakaotalk member kick <chat-id> <user-id> --force --pretty
agent-kakaotalk member kick <chat-id> <user-id> --force --account <account-id>

# List members on the room's kick list (blocked from rejoining)
agent-kakaotalk member kick-list <chat-id>
agent-kakaotalk member kick-list <chat-id> --pretty
agent-kakaotalk member kick-list <chat-id> --account <account-id>

# Remove a member from the kick list so they can rejoin (does not re-add them)
agent-kakaotalk member unkick <chat-id> <user-id>
agent-kakaotalk member unkick <chat-id> <user-id> --pretty
agent-kakaotalk member unkick <chat-id> <user-id> --account <account-id>

Get <user-id> from member list (user_id) or from message list (author_id).

member kick without --force:

{
  "warning": "Kicking is irreversible and blocks the member from rejoining. Use --force to confirm.",
  "action": "kick",
  "chat_id": "9876543210",
  "user_id": "1234567890"
}

member kick --force and member unkick:

{ "success": true, "status_code": 0, "chat_id": "9876543210", "user_id": "1234567890" }

member kick-list:

{
  "success": true,
  "status_code": 0,
  "chat_id": "9876543210",
  "members": [{ "user_id": "1234567890", "nickname": "Alice", "chat_id": "9876543210", "kicked_at": null }]
}

Agent rule: Never pass --force to member kick unless the user explicitly asked to kick that specific member. Confirm the target with member list first.

Message Commands

Uncertain sends are not automatically replayed by default. delivery_unknown

means the message may already have been delivered. Explicitly opt into one retry

only when duplicate delivery is acceptable:

agent-kakaotalk message send <chat-id> "Hello" --retry-unknown-delivery
agent-kakaotalk message upload <chat-id> ./report.pdf --retry-unknown-delivery

The opt-in can duplicate messages or uploads; it does not retry every provider

rejection or generic error. See Pattern 11 in references/common-patterns.md.

SDK protocol-field defaults/overrides and evidence limits are documented in

the SDK guide.

# List messages in a chat room
agent-kakaotalk message list <chat-id>
agent-kakaotalk message list <chat-id> -n 50
agent-kakaotalk message list <chat-id> --from <log-id>
agent-kakaotalk message list <chat-id> --pretty

# Read history losslessly, oldest first, one page at a time
agent-kakaotalk message page <chat-id> --from <log-id>
agent-kakaotalk message page <chat-id> --from <log-id> -n 50
agent-kakaotalk message page <chat-id> --pretty

# Send a text message
agent-kakaotalk message send <chat-id> "Hello world"
agent-kakaotalk message send <chat-id> "Hello world" --pretty

# Send a quoted reply to a specific message (use a log_id from `message list`)
agent-kakaotalk message send <chat-id> "Replying to this" --reply-to <log-id>

# Mention (tag) a member; the text must contain @<name>
agent-kakaotalk message send <chat-id> "@Alice hello" --mention <user-id>
agent-kakaotalk message send <chat-id> "@Alice hello" --mention <user-id>:Alice

# Send a quoted reply when you already have the target message (no history lookup)
agent-kakaotalk message send <chat-id> "Replying to this" \
  --reply-to-json '{"log_id":"<log-id>","author_id":<author-id>,"message":"<target text>","type":1}'

# Send a file (auto-routes by MIME: photo / video / audio / generic file)
agent-kakaotalk message upload <chat-id> ./photo.jpg
agent-kakaotalk message upload <chat-id> ./clip.mp4
agent-kakaotalk message upload <chat-id> ./voice.m4a
agent-kakaotalk message upload <chat-id> ./report.pdf

# Send a multi-photo gallery (2+ images in one message)
agent-kakaotalk message upload <chat-id> ./img1.jpg ./img2.jpg ./img3.jpg

# Force a specific kind (override auto-routing)
agent-kakaotalk message upload <chat-id> ./clip.mp4 --as file       # send as generic file, not video
agent-kakaotalk message upload <chat-id> ./image --as photo         # extension-less file
agent-kakaotalk message upload <chat-id> ./data.bin --mime application/octet-stream

# Mark messages as read up to a given log ID
agent-kakaotalk message mark-read <chat-id> <log-id>
agent-kakaotalk message mark-read <chat-id> <log-id> --pretty
agent-kakaotalk message mark-read <chat-id> <log-id> --link-id <li>   # open chats only

# Show the typing indicator ("..." dots) in a chat room for ~5s
agent-kakaotalk message typing <chat-id>
agent-kakaotalk message typing <chat-id> --pretty
agent-kakaotalk message typing <chat-id> --link-id <li>   # open chats only

# Use a specific account
agent-kakaotalk message list <chat-id> --account <account-id>
agent-kakaotalk message page <chat-id> --from <log-id> --account <account-id>
agent-kakaotalk message send <chat-id> "Hello" --account <account-id>
agent-kakaotalk message upload <chat-id> ./photo.jpg --account <account-id>
agent-kakaotalk message mark-read <chat-id> <log-id> --account <account-id>
agent-kakaotalk message typing <chat-id> --account <account-id>

message send prints the send result (success, status_code, chat_id, log_id, sent_at). Like upload, mark-read, and typing, the process exits non-zero when success is false, so shell scripts can branch on the exit code as well as on the JSON.

Replying to a Message

--reply-to <log-id> sends the text as a quoted reply that references an existing message. Get the log_id from message list output. The CLI looks up the target in the chat's recent history (latest 100 messages) to build the quote, so the target must be reasonably recent. If it is not there, the command fails with code: "reply_target_not_found" without sending.

# Find the message you want to reply to
agent-kakaotalk message list <chat-id> -n 50

# Reply to it by its log_id
agent-kakaotalk message send <chat-id> "Good point!" --reply-to 1234567890

If the log_id is not found in the latest 100 messages, the command errors out without sending.

--reply-to-json <json> skips that lookup when you already hold the target message, for example a message event from the listener or a row from an earlier message list. Pass a JSON object with log_id, author_id, message, and type (the listener event calls it message_type). Extra fields such as author_name are ignored, so a message list row works as is. Because nothing is looked up, the target can be older than the latest 100 messages, and the send needs no MCHATLOGS/SYNCMSG round trips. The CLI does not check that the target exists or that the fields match it: the quote shows whatever you pass.

# Reply to a message you already have, even an old one
agent-kakaotalk message send <chat-id> "Good point!" \
  --reply-to-json '{"log_id":"3947068532267313155","author_id":7,"message":"original text","type":1}'

# Pipe a row straight from message list
TARGET=$(agent-kakaotalk message list <chat-id> -n 1 | jq -c '.[0]')
agent-kakaotalk message send <chat-id> "Replying to the latest message" --reply-to-json "$TARGET"

In open chats (오픈채팅) the reply also carries the room's link id as src_linkId. The CLI resolves it on its own: from the login snapshot when the room is there, otherwise through a read-only CHATINFO lookup that does not change read state. You never pass --link-id for a reply. The open-chat reply bubble itself has not been checked against a live server yet.

A send counts as delivered only when the server returns a non-zero log_id. A WRITE acknowledgment with status_code: 0 but log_id: "0" is reported as "success": false and the process exits non-zero, because no message was created.

Mentioning Users

--mention <user-id> tags a member so KakaoTalk renders the @name as a mention and notifies them. The text must already contain @<name> for every mentioned user. Repeat the flag to tag several users. The CLI also accepts --mention together with --reply-to, but mentions inside a quoted reply have not yet been verified against a live server.

# Name is looked up from the chat's member list (the member's nickname in this chat)
agent-kakaotalk message send <chat-id> "@Alice the build is green" --mention 1234567890

# Pass the name explicitly as <user-id>:<name> (no member lookup)
agent-kakaotalk message send <chat-id> "@Alice @Bob standup in 5" --mention 1234567890:Alice --mention 2345678901:Bob

# Mention inside a quoted reply
agent-kakaotalk message send <chat-id> "@Alice agreed" --reply-to <log-id> --mention 1234567890:Alice
Sending Attachments

message upload sends photos, videos, audio, and arbitrary files to a chat. The CLI sniffs the MIME type from the filename and dispatches to the matching KakaoTalk message type, so the common case is a single command and a file path:

agent-kakaotalk message upload <chat-id> ./report.pdf

Routing rules:

| Filename / MIME | Sent as | KakaoTalk renders it as |

| --- | --- | --- |

| image/* (.jpg, .png, .gif, .webp) | photo | Inline image with tap-to-zoom |

| video/* (.mp4, .mov, .webm) | video | Inline player with play button |

| audio/* (.m4a, .mp3, .wav, .ogg) | audio | Voice-message bubble with waveform |

| anything else | file | Generic file attachment with download icon |

Multi-photo galleries (one message that contains several images): pass 2+ files and the CLI uses the gallery flow automatically.

agent-kakaotalk message upload <chat-id> ./img1.jpg ./img2.jpg ./img3.jpg

Override the auto-routing with --as <photo|video|audio|file|multi> when you need explicit control — for example, to send an .mp4 as a generic downloadable file instead of an inline video. Use --mime <type> to override MIME detection (handy for extension-less files or when the caller knows better than the filename).

Output (JSON by default; --pretty pretty-prints the same JSON):

{ "success": true, "status_code": 0, "chat_id": "9876543210", "log_id": "3846830417126748160", "sent_at": 1779509936 }

The process exits non-zero when success is false.

Notes:

Read Status

The read-status API is SDK-only: getReadWatermarks(chatId) seeds each member's

last-read log_id, and computeReadStatus(...) reports who has read a message.

A member counts as having read it iff watermark >= log_id; always exclude the

message sender (and any other caller-selected IDs) from the calculation.

getReadWatermarks sends CHATONROOM, a room-entry call that may clear your own

unread count (#315), and the server returns watermarks only on the first

CHATONROOM for a chat in a session. Call it once per chat per LOCO session.

The result is a snapshot the SDK never updates: store it yourself and advance

each watermark from listener read events (DECUNREAD pushes), only ever

forward. Do not poll CHATONROOM. On disconnected, drop the stored

watermarks; after the reconnect you may seed each chat once again.

Mark as Read

message mark-read sends a LOCO NOTIREAD packet to advance the server-side read watermark for a chat. The watermark is a log_id — typically the latest message's log_id from message list — not a timestamp.

Output (JSON by default; --pretty pretty-prints the same JSON):

{ "success": true, "status_code": 0, "chat_id": "9876543210", "watermark": "123456789" }

The process exits non-zero when success is false so shell scripts can branch on it.

Notes:

Typing Indicator

message typing sends one LOCO ACTION packet (typing subtype) so the other members see the animated "..." indicator. It does not create a message and does not change read state.

Output (JSON by default; --pretty pretty-prints the same JSON):

{ "success": true, "status_code": 0, "chat_id": "9876543210" }

Errors are printed as {"error": "..."} (plus code when available, see Error Handling) and the process exits non-zero:

Notes:

Message List Output

Each message includes:

Fetching More Messages

The CLI handles internal pagination automatically. Just increase -n to get more messages. Pagination is capped at ~4,000 raw messages (50 pages × 80 per page). If the cap is hit, a warning is printed to stderr and results may be incomplete.

# Get latest 20 messages (default)
agent-kakaotalk message list 9876543210

# Get 50 messages
agent-kakaotalk message list 9876543210 -n 50

# Get 200 messages
agent-kakaotalk message list 9876543210 -n 200

# Get messages newer than a known log ID (forward only)
agent-kakaotalk message list 9876543210 --from 123456789

message list --from returns the latest N messages after the cursor. If more than N messages arrived since that point, the older ones in between are not in the output. When you need every message after a known point (catching up, collecting a range for a summary), use message page instead.

Paging History Without Gaps

message page returns one page of messages strictly after --from <log-id>, sorted oldest first. It never drops the middle of a range: if more than -n messages are available, it returns the oldest -n and sets complete to false, so you continue from next_cursor.

| Flag | Default | Description |

| ---- | ------- | ----------- |

| --from <log-id> | start of available history | Exclusive cursor. Only messages with a larger log_id are returned. |

| -n, --count <number> | 100 | Page size, an integer from 1 to 100. Other values are rejected before login. |

| --account <id> | current account | Use a specific KakaoTalk account. |

| --pretty | off | Pretty print JSON output. |

Output:

{
  "messages": [
    {
      "log_id": "123456790",
      "type": 1,
      "author_id": 1234567890,
      "author_name": "Alice",
      "message": "Hello",
      "attachment": null,
      "sent_at": 1700000000000
    }
  ],
  "next_cursor": "123456790",
  "complete": false
}
CURSOR=123456789
while :; do
  PAGE=$(agent-kakaotalk message page 9876543210 --from "$CURSOR") || exit 1
  echo "$PAGE" | jq -c '.messages[]'
  [ "$(echo "$PAGE" | jq -r '.complete')" = "true" ] && break
  NEXT=$(echo "$PAGE" | jq -r '.next_cursor // empty')
  [ -z "$NEXT" ] && { echo "message page: complete=false but no next_cursor; history may be incomplete" >&2; exit 1; }
  CURSOR=$NEXT
done

Notes:

Output Format

JSON (Default)

All commands output JSON by default for AI consumption:

{
  "chat_id": "9876543210",
  "type": 2,
  "display_name": "Alice, Bob",
  "title": null,
  "active_members": 3,
  "unread_count": 5,
  "last_message": {
    "author_id": 1111111111,
    "author_name": "Alice",
    "message": "Hello everyone!",
    "sent_at": 1705312200000
  }
}

Pretty (Human-Readable)

Use --pretty flag for formatted output:

agent-kakaotalk chat list --pretty

Global Options

| Option | Description |

| ----------- | ------------------------------------------------------------ |

| --account | Use a specific KakaoTalk account (default: current account) |

| --pretty | Human-readable output instead of JSON |

Common Patterns

See references/common-patterns.md for typical AI agent workflows.

Templates

See templates/ directory for runnable examples:

Error Handling

Errors raised while a command runs go through the shared error handler: they are printed to stderr as JSON and the process exits non-zero:

{
  "error": "LOCO packet timeout: GETMEM (15000ms)"
}

Some failures do not go through that handler, so check the exit code first and read both streams:

When the underlying error carries a machine-readable code, it is included as code. Branch on code rather than matching the English error text, which may change. Errors without a code (like the one above) omit the field.

{
  "error": "Reply target log-id 1234567890 not found in the latest 100 messages of chat 9876543210",
  "code": "reply_target_not_found"
}

Codes you are likely to see:

Common errors:

Configuration

Credentials stored in ~/.config/agent-messenger/kakaotalk-credentials.json (0600 permissions). See references/authentication.md for format and security details.

Config format:

{
  "current_account": "1234567890",
  "accounts": {
    "1234567890": {
      "account_id": "1234567890",
      "oauth_token": "...",
      "user_id": "1234567890",
      "refresh_token": "...",
      "device_uuid": "...",
      "device_type": "tablet",
      "created_at": "2025-01-15T10:30:00.000Z",
      "updated_at": "2025-01-15T10:30:00.000Z"
    }
  }
}

SDK: Programmatic Usage

KakaoTalkClient is available as a TypeScript SDK for building scripts and automations.

Setup

import { KakaoTalkClient } from 'agent-messenger/kakaotalk'

const client = await new KakaoTalkClient().login()

Or with manual credential management:

import { KakaoTalkClient, KakaoCredentialManager } from 'agent-messenger/kakaotalk'

const manager = new KakaoCredentialManager()
const account = await manager.getAccount()
if (!account) throw new Error('Not authenticated')

const client = await new KakaoTalkClient().login({ oauthToken: account.oauth_token, userId: account.user_id, deviceUuid: account.device_uuid })

For caller-managed token renewal, use the explicit SDK primitive:

import { refreshKakaoOAuthToken } from 'agent-messenger/kakaotalk'

if (!account.refresh_token) throw new Error('No KakaoTalk refresh token')

const refreshed = await refreshKakaoOAuthToken({
  accessToken: account.oauth_token,
  refreshToken: account.refresh_token,
  deviceUuid: account.device_uuid,
})

const nextAccount = {
  ...account,
  oauth_token: refreshed.accessToken,
  refresh_token: refreshed.refreshToken,
  updated_at: new Date().toISOString(),
}

// Persist nextAccount atomically before another client uses this credential.
// The refresh primitive intentionally does not write credential files or retry login.

Kakao can rotate the refresh token. Never refresh a copied production credential and discard the returned token set. See references/authentication.md for error codes and the controlled canary procedure.

Example

try {
  // Get your profile
  const profile = await client.getProfile()

  // List chats
  const chats = await client.getChats()

  // Send a message
  if (chats.length === 0) throw new Error('No chats found')
  const chatId = chats[0].chat_id
  const result = await client.sendMessage(chatId, 'Hello from SDK!')

  // Send a file (photo / video / audio / file auto-routed by MIME). Pass
  // an array to send several at once — all-image arrays become a gallery.
  const photo = await Bun.file('./photo.jpg').bytes()
  await client.sendAttachment(chatId, photo, 'photo.jpg')

  // Read messages
  const messages = await client.getMessages(chatId, { count: 50 })

  // Reply to a message by quoting it
  const target = messages[messages.length - 1]
  await client.sendMessage(chatId, 'Replying to your last message', {
    replyTo: { log_id: target.log_id, author_id: target.author_id, message: target.message, type: target.type },
  })
  // Optional: pass link_id (open chats) to skip the link id lookup
} finally {
  // Always close when done (LOCO TCP connection)
  client.close()
}

Full API Reference

See the KakaoTalk SDK documentation for complete method signatures, types, schemas, and examples.

Limitations

Troubleshooting

`agent-kakaotalk: command not found`

agent-kakaotalk is NOT the npm package name. The npm package is agent-messenger.

If the package is installed globally, use agent-kakaotalk directly:

agent-kakaotalk chat list --pretty

If the package is NOT installed, use --package to install and run:

npx -y --package agent-messenger agent-kakaotalk chat list --pretty
bunx --package agent-messenger agent-kakaotalk chat list --pretty
pnpm dlx --package agent-messenger agent-kakaotalk chat list --pretty

Note: If the user prefers a different package runner, use the matching command above.

NEVER run npx agent-kakaotalk, bunx agent-kakaotalk, or pnpm dlx agent-kakaotalk without --package agent-messenger. It will fail or install a wrong package since agent-kakaotalk is not the npm package name.

Password prompt on fresh install

On fresh installs, the desktop app (macOS or Windows) may hash or omit the password from its cache, so the CLI cannot extract it automatically. The CLI will prompt for the password once to register the device — via a native dialog on macOS (AppKit), Windows (PowerShell WinForms), or Linux (zenity / kdialog), or via a TTY prompt if a terminal is available. After registration, the password is never needed again.

On Linux there is no desktop app to extract from, so always provide credentials explicitly:

agent-kakaotalk auth login --email user@example.com --password-file /tmp/.kakao-pw

--password-file reads the file then immediately deletes it, so the password never appears in shell history or process listings.

When the CLI returns {"next_action": "run_interactive", ...}, use a tmux session to let the user type their password securely. See "Handling run_interactive" above for the exact steps.

NEVER ask for the password in chat or pass it via --password — this exposes the plaintext password in conversation logs, shell history, and process lists.

Bad credentials

If login returns bad_credentials, the provided password is incorrect. Do NOT retry with --force or switch device slots — the issue is the credentials themselves, not the device slot.

If the issue persists, run with --debug to see the full server response.

Device slot occupied

If login fails because the tablet slot is occupied (error: login_failed, not bad_credentials):

# Option 1: Use the PC slot instead
agent-kakaotalk auth login --device-type pc --force

# Option 2: Force the tablet slot (kicks existing tablet session)
agent-kakaotalk auth login --device-type tablet --force

Passcode verification timeout

If the passcode expires before you confirm on your phone:

  1. Run agent-kakaotalk auth login again — a new passcode will be generated
  2. Confirm the code on your phone within the time limit
  3. The CLI automatically completes login after confirmation

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.