Skip to content

Commit 871e23c

Browse files
authored
Merge pull request #14 from wildjames/codex/troubleshoot-unprompted-bot-dms
Fix self-message check
2 parents 93bfc85 + 4b16383 commit 871e23c

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

signal_interface/signal_consumer.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import asyncio
1212
import json
13+
import re
1314
from logging import getLogger
1415
from typing import Any, Dict, List, Union
1516

@@ -34,6 +35,11 @@
3435
logger = getLogger(__name__)
3536

3637

38+
def _normalize_number(number: str) -> str:
39+
"""Normalize a phone number by stripping all non-digit characters."""
40+
return re.sub(r"\D", "", number)
41+
42+
3743
class SignalConsumer:
3844
"""The consumer class handles checking for new messages, and placing them
3945
on the queue.
@@ -282,7 +288,10 @@ async def _process_incoming(self, message: Dict[str, Any]):
282288
# back messages that we've just sent (sync messages), which can cause
283289
# the Razzler to respond to its own messages. This manifests as the bot
284290
# sending apparently unprompted direct messages.
285-
if msg.envelope.sourceNumber == self.signal_info.phone_number:
291+
if (
292+
_normalize_number(msg.envelope.sourceNumber)
293+
== _normalize_number(self.signal_info.phone_number)
294+
):
286295
logger.debug("Ignoring message sent by ourselves")
287296
return
288297

0 commit comments

Comments
 (0)