fix: clear typing indicator after sending reply in self-chat mode

This commit is contained in:
linuztx 2026-03-26 15:43:01 +08:00
parent 7c653c9d56
commit 18c5716d10
3 changed files with 10 additions and 4 deletions

View file

@ -258,6 +258,9 @@ async def send_wa_reply(
except Exception as e:
PrintStyle.warning(f"WhatsApp: attachment error: {e}")
# Clear typing indicator
await wa_client.send_typing(base_url, chat_id, paused=True)
return None

View file

@ -56,12 +56,15 @@ async def send_media(
return await resp.json()
async def send_typing(base_url: str, chat_id: str) -> None:
async def send_typing(base_url: str, chat_id: str, paused: bool = False) -> None:
try:
payload: dict = {"chatId": chat_id}
if paused:
payload["status"] = "paused"
async with aiohttp.ClientSession() as session:
async with session.post(
f"{base_url}/typing",
json={"chatId": chat_id},
json=payload,
timeout=aiohttp.ClientTimeout(total=5),
) as resp:
await resp.json()

View file

@ -547,11 +547,11 @@ app.post('/typing', async (req, res) => {
return res.status(503).json({ error: 'Not connected' });
}
const { chatId } = req.body;
const { chatId, status } = req.body;
if (!chatId) return res.status(400).json({ error: 'chatId required' });
try {
await sock.sendPresenceUpdate('composing', chatId);
await sock.sendPresenceUpdate(status === 'paused' ? 'paused' : 'composing', chatId);
res.json({ success: true });
} catch (err) {
res.json({ success: false });