Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions app/bot/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
wiring lives in bot/main.py.
"""

from html import escape
from typing import Any

import structlog
Expand Down Expand Up @@ -71,14 +72,15 @@ async def subscribe(session: Any, settings: Settings, telegram_user_id: int) ->
intro = "🔑 Your new API key" if created else "🔑 Your API key (rotated)"
return (
f"{intro} — save it securely; it's shown only once:\n\n"
f"`{raw_key}`\n\n"
"*📡 Supported platforms:*\n"
f"`<code>{raw_key}</code>`\n\n"
"<b>📡 Supported platforms:</b>\n"
"• Telegram\n"
"• Slack\n"
"• Discord\n"
"• Custom Webhooks\n\n"
f"⚙️ Configure them here: [here]({link})\n\n"
"*🚀 Send notifications:*\n"
f"• Endpoint: `{base_url}/api/v1/notify`\n"
"• Header: `X-API-Key`"
f"⚙️ Configure them here: "
f'<a href="{escape(link, quote=True)}">here</a>\n\n'
"<b>🚀 Send notifications:</b>\n"
f"• Endpoint: `<code>{{base}}/api/v1/notify</code>`\n"
"• Header: `<code>X-API-Key</code>`"
)
6 changes: 3 additions & 3 deletions app/bot/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ def _msg(update: Update) -> Any:


async def _cmd_start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
await _msg(update).reply_text(WELCOME, parse_mode=ParseMode.MARKDOWN_V2)
await _msg(update).reply_text(WELCOME, parse_mode=ParseMode.HTML)


async def _cmd_help(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
await _msg(update).reply_text(HELP, parse_mode=ParseMode.MARKDOWN_V2)
await _msg(update).reply_text(HELP, parse_mode=ParseMode.HTML)


async def _cmd_subscribe(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
Expand All @@ -32,7 +32,7 @@ async def _cmd_subscribe(update: Update, context: ContextTypes.DEFAULT_TYPE) ->
async with SessionLocal() as session:
text = await subscribe(session, settings, telegram_user_id)
await session.commit()
await _msg(update).reply_text(text, parse_mode=ParseMode.MARKDOWN_V2)
await _msg(update).reply_text(text, parse_mode=ParseMode.HTML)


def create_application() -> Application:
Expand Down
8 changes: 4 additions & 4 deletions tests/test_bot_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ async def _run() -> str:

text = anyio.run(_run)
assert "Your new API key" in text
assert "`rn_" in text
assert "<code>rn_" in text
assert "rapid.example/api/channels/entry/" in text

async def _check() -> m.User | None:
Expand All @@ -63,7 +63,7 @@ async def _check() -> m.User | None:
assert isinstance(user, m.User)
assert len(user.api_key_hash) == 64
# exactly one key occurrence (shown once)
assert len(re.findall(r"`rn_[^`]+`", text)) == 1
assert len(re.findall(r"<code>rn_[^<]+</code>", text)) == 1


def test_subscribe_again_rotates_key(tmp_path) -> None:
Expand All @@ -78,8 +78,8 @@ async def _run(subscribe_id: int) -> str:
first = anyio.run(_run, 888)
second = anyio.run(_run, 888)
assert "rotated" in second
raw_first = re.search(r"`(rn_[^`]+)`", first).group(1)
raw_second = re.search(r"`(rn_[^`]+)`", second).group(1)
raw_first = re.search(r"<code>(rn_[^<]+)</code>", first).group(1)
raw_second = re.search(r"<code>(rn_[^<]+)</code>", second).group(1)
assert raw_first != raw_second

async def _count() -> int:
Expand Down
Loading