Skip to main content

kakaotalk-bot (Python)

KakaoTalk Bot API client for Python 3.10+: REST API wrapper (async + sync), Gateway (WebSocket) client and webhook helpers. Depends on httpx and websockets.

pip install kakaotalk-bot

REST API

from kakaotalk_bot import (
    KakaoBotClient, KakaoBotSyncClient, KakaoBotApiError,
    text_response, SkillResponseBuilder, basic_card, web_link_button, message_button, mention_tag,
)

async with KakaoBotClient(BOT_TOKEN) as client:
    await client.send_callback(callback_token, text_response("처리가 완료되었습니다."))
    await client.send_to_group(bot_group_key, text_response("안녕하세요!"))
    await client.send_to_user(bot_user_key, text_response("안녕하세요!"))  # channel chat only

    commands = await client.get_commands()
    await client.update_commands([{"buttonName": "도움말"}, {"buttonName": "상담원 연결", "description": "상담원과 연결합니다."}])
    await client.update_guide("🤖 저와 함께 이런 것들을 할 수 있어요.")

    response = (
        SkillResponseBuilder()
        .text(f"안녕하세요 {mention_tag('u1')}!")
        .mention("u1", bot_user_key)
        .add(basic_card("제목", "설명", {"imageUrl": "https://example.com/a.png"},
                        [web_link_button("열기", "https://example.com"), message_button("다시")]))
        .quick_reply("도움말")
        .build()
    )
    try:
        await client.send_callback(callback_token, response)
    except KakaoBotApiError as e:
        if e.is_callback_token_error:  # -881
            ...

# Blocking variant with the same methods
with KakaoBotSyncClient(BOT_TOKEN) as client:
    client.send_to_group(bot_group_key, text_response("hi"))

Options: KakaoBotClient(token, base_url=..., timeout=10.0, headers=..., http=httpx.AsyncClient(...)).

Gateway (WebSocket)

import asyncio
from kakaotalk_bot import KakaoBotGateway, DispatchEvent

gateway = KakaoBotGateway(
    BOT_TOKEN,
    # url=..., client=..., auto_reconnect=True, initial_backoff=1.0, max_backoff=30.0,
    # heartbeat_margin=5.0, handshake_timeout=15.0,
)

@gateway.on("ready")
def on_ready(ready):
    print("bot", ready["bot"]["id"], "session", ready["session_id"])

@gateway.on("MESSAGE_CREATE")
async def on_message(event: DispatchEvent):
    # event.data: {"id", "content", "timestamp", "isChannelChatroom", "botGroupKey", "botUserKey", "callbackToken"?}
    if event.can_reply:
        await event.reply_text(f"echo: {event.content}")

@gateway.on("error")
def on_error(exc):
    print("gateway error:", exc)  # fatal close codes: exc.fatal is True

asyncio.run(gateway.run())          # blocks; reconnects automatically
# or: task = await gateway.start()  # background task, returns once READY
#     await gateway.close()

Events: ready, resumed, dispatch, MESSAGE_CREATE, ENTRANCE, CHAT_JOIN, LEAVE, AD_REWARD, close, reconnecting, heartbeat_timeout, error. Listeners may be sync or async.

Session persistence: save gateway.session and call gateway.restore_session(session_id, last_seq) before run() to RESUME across process restarts.

Webhook (FastAPI example)

from fastapi import FastAPI, Request, Response, BackgroundTasks
from kakaotalk_bot import KakaoBotClient, parse_webhook_event, verify_custom_header

client = KakaoBotClient(BOT_TOKEN)
app = FastAPI()

@app.post("/webhook")
async def webhook(request: Request, background: BackgroundTasks) -> Response:
    if not verify_custom_header(request.headers.get("X-My-Secret"), WEBHOOK_SECRET):
        return Response(status_code=401)
    event = parse_webhook_event(await request.body(), client)
    if event.type == "MESSAGE_CREATE" and event.can_reply:
        background.add_task(event.reply_text, f"echo: {event.content}")
    return Response(status_code=204)  # within 1 second

Development

pip install -e ".[dev]"
pytest
mypy kakaotalk_bot

Metadata

Release files for kakaotalk-bot 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kakaotalk-bot 0.1.0
File Size Uploaded Provenance Actions
kakaotalk_bot-0.1.0.tar.gz 18.9 kB With provenance Details for kakaotalk_bot-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for kakaotalk-bot 0.1.0
File Interpreter ABI Platform Actions
kakaotalk_bot-0.1.0-py3-none-any.whl Python 3 none any Details for kakaotalk_bot-0.1.0-py3-none-any.whl

Total release size: 39.5 kB

Release files / kakaotalk_bot-0.1.0.tar.gz

Download URL kakaotalk_bot-0.1.0.tar.gz
Size 18.9 kB
Tags Source
SHA-256 checksum
How to use checksums
21bab263050a6465389bc316a4bbf0166f8210790cbd6f0cf3b7aed9bbacba61
BLAKE2b-256 checksum
How to use checksums
66efb13fbc83f93b9cf735abc9bfe968815ef3025b1120bcbe77c64418f00f6d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

Release files / kakaotalk_bot-0.1.0-py3-none-any.whl

Download URL kakaotalk_bot-0.1.0-py3-none-any.whl
Size 20.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
03911281c6639575fffd4a6c80e9978eca671d8210d81415347f6e17ded44c1d
BLAKE2b-256 checksum
How to use checksums
75516fed307c8e3aac63d67df60fcace9cd5a743d0d8aae94111ff98034ca95b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

Security for kakaotalk-bot 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for kakaotalk_bot-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page