# KakaoTalk Short Summary Integration

## Delivery Mode

Use Kakao Developers `나에게 기본 템플릿으로 메시지 발송`.

This sends the short version of the US equity analyst report to the authenticated Kakao account's `나와의 채팅방`.

## Cost And Quota Check

As of the Kakao Developers quota documentation checked on 2026-06-06:

- KakaoTalk Message has a free daily quota of 30,000 calls.
- The documented per-user limits include 100 per sender, 100 per recipient, and 20 per sender/recipient pair.
- This automation sends 2 messages per trading day, so it is far below the conservative 20-per-day sender/recipient-pair limit.
- The paid additional quota table lists KakaoTalk Share, not KakaoTalk Message `나에게 보내기`.
- Treat this as no-cost for this personal 2-6 messages daily use case unless Kakao changes its quota/pricing policy or paid API settings are enabled.
- Check Kakao Developers `[My Applications] > [Statistics] > [Quotas]` periodically.

## Required Kakao Setup

1. Create or open an app in Kakao Developers.
2. Enable Kakao Login.
3. Add the consent scope `카카오톡 메시지 전송(talk_message)`.
4. Register a redirect URI, for example `http://localhost:8080/oauth`.
5. Get a refresh token through Kakao OAuth with the `talk_message` scope.
6. Use `/Users/jangbogeun/Documents/Codex/2026-06-06/2/outputs/kakao_oauth_helper.py` to generate the auth URL and exchange the returned code.
7. Store credentials in macOS Keychain:

```bash
python3 /Users/jangbogeun/Documents/Codex/2026-06-06/2/outputs/kakao_keychain_setup.py set
```

8. Environment variables also work for temporary testing:

```bash
KAKAO_REST_API_KEY=...
KAKAO_REFRESH_TOKEN=...
KAKAO_CLIENT_SECRET=... # only if your app uses a client secret
KAKAO_LINK_URL=https://finance.yahoo.com
```

`send_kakao_memo.py` checks environment variables first and then macOS Keychain service `codex-us-equity-kakao`.
If `KAKAO_LINK_URL` is accidentally set to `http://localhost:8080` or another local OAuth URL, the sender now ignores it and falls back to `https://finance.yahoo.com`.

Important: `localhost` is only valid on the machine running the dashboard. A KakaoTalk link opened on a phone cannot open the Mac's local dashboard unless the dashboard is published to a reachable URL or exposed through a private tunnel.

## Local Test

```bash
python3 /Users/jangbogeun/Documents/Codex/2026-06-06/2/outputs/send_kakao_memo.py \
  --title "US Equity Analyst 테스트" \
  --message "테스트: 시장 regime 관찰, SOXL 예수금 준비 없음." \
  --button-title "상세 보기" \
  --dry-run
```

Remove `--dry-run` after Kakao credentials are configured in Keychain or environment variables.

## Message Format

Every scheduled report should produce a `KAKAO_SHORT_SUMMARY` block. Default format is the 6-line situation summary under 450 Korean characters:

```text
[상황] DEFENSE / RECOVERY / ATTACK / CASH / AH-URGENT
계좌: 본/부/합산, 시작대비, 현금준비
시장: 핵심 원인 1-2개, 강한 축/약한 축
행동: 지금 할 일 1-2개
금지: 하면 안 되는 행동 1-2개
다음: 확인 시각 또는 트리거
```

Detailed reports can still include market, volatility, event, SOXL/SOXS, risk, and cash sections, but KakaoTalk should keep the fixed order above unless it is an emergency.

Full format guide: `/Users/jangbogeun/Documents/Codex/2026-06-06/2/outputs/situation_summary_format.md`

## Notes

- The self-message API sends only to the authenticated user's own KakaoTalk chatroom.
- Sending to friends or channel subscribers requires additional Kakao permissions or Kakao Business products.
- Do not store Kakao tokens in tracked documents.
