Replies: 4 comments 9 replies
-
I haven't tried it yet, but maybe it would be easier to do something like this in a scripting language like Python?
I guess that is something that we could add 👍 |
Beta Was this translation helpful? Give feedback.
-
+1 for this feature! I found this discussion after trying to solve the exact same problem: creating a real-time, event-driven way to handle incoming messages in json-rpc mode. A native, built-in JSON forwarder that calls a specified webhook endpoint, as suggested in this issue, would be a game-changing feature for many automation use cases (like in my case integrating with n8n). Thanks for your great work! |
Beta Was this translation helpful? Give feedback.
-
will be part of the next release. If you want to do some early testing, let me know. I can provide you a test version |
Beta Was this translation helpful? Give feedback.
-
I wanted to reach out with gratitude for your excellent work on the this project, specifically this webhook functionality. Thanks to the guidance provided here, I was able to successfully implement a robust webhook-based messaging system for my project. Implementation DetailsHere's how I integrated it: Docker Configuration# docker-compose.yml
signal_cli:
image: bbernhard/signal-cli-rest-api:0.191-dev
environment:
- MODE=json-rpc
- WEBHOOK_URL=http://server:8000/api/signal/webhook
ports:
- "8080:8080"
volumes:
- signal_cli_config:/home/.local/share/signal-cli
depends_on:
- server Python Webhook Handler Example# signal_webhook.py
from fastapi import APIRouter, Request
import structlog
router = APIRouter()
logger = structlog.get_logger(__name__)
@router.post("/api/signal/webhook")
async def handle_signal_webhook(request: Request):
"""Handle incoming Signal webhook events"""
try:
payload = await request.json()
# Handle different webhook event types
if payload.get("method") == "receive":
params = payload.get("params", {})
if "envelope" in params:
envelope = params["envelope"]
# Extract message details
if "dataMessage" in envelope:
message = envelope["dataMessage"].get("message", "")
source_number = envelope.get("sourceNumber", "")
timestamp = envelope.get("timestamp")
# Process the message through AI system
await process_incoming_message(
phone_number=source_number,
message=message,
timestamp=timestamp
)
return {"status": "processed"}
# Handle other event types (typing indicators, receipts, etc.)
return {"status": "ignored", "reason": "non_message_event"}
except Exception as e:
logger.error("Webhook processing error", error=str(e))
return {"status": "error", "message": str(e)} Please let me know if/when this gets merged into the mainline. Thank you so much it worked great! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I use the json-rpc implementation (with @haberda addon), and I would like to send events to Home Assistant to get the messages.
I tried many combinations of commands and the best thing I managed to get is this one liner.
wscat -c 10.0.0.9:8080/v1/receive/+XXXXXXXX --slash | jq --unbuffered -c -r '.envelope | select( .dataMessage != null)' | sed -u "s/^/'/;s/$/'/" | xargs -I{} curl -N -d '{}' -H "Content-Type: application/json" -X POST http://10.0.0.9:8123/api/webhook/-XXXXXXXXXXXXXXXXX
select( .dataMessage != null)
is used to exclude "Start typing / Stop typing" messages.It mainly works but because of xargs, it fails for specific cases like the presence of unmatching single quote. I didn't manage to find a proper way to fully escape the messages.
So, I can get the messages as events in HA, parse them and do what I want with them:
{{ trigger.json.sourceName }} says "{{ trigger.json.dataMessage.message }}"
Any idea to have a better / easiest way to do it?
Would it make sense to have such JSON forwarder implemented in this project as an advanced option? The minimal implementation would be to specify the webhook endpoint. The filtering of messages would be the responsibility of the receiving client.
Beta Was this translation helpful? Give feedback.
All reactions