12 Commits
0.1.0 ... 0.1.3

6 changed files with 128 additions and 48 deletions

View File

@@ -31,3 +31,32 @@ action: whatsapp_bridge_integration.send_message
data:
number: "491701234567"
message: "The washing machine is finished! 🧺"
```
### Use in Node-RED
Add a Call Service (or Action) node.
Domain: whatsapp_bridge_integration
Service: send_message
Data:
```JSON
{
"number": "491701234567",
"message": "{{payload}}"
}
```
## 👥 Multi-Account Support (Coming Soon)
We are currently working on a UI-based configuration flow so you can save "Account Aliases" (like "Dad", "Work", "Security") and select them from a dropdown menu without typing the phone number every time.
##⚠️ Important Notes
Phone Numbers: Always use the international format without + or 00 (e.g., 49... for Germany).
Local Network: The integration communicates locally with the Add-on on port 3000.
Developed by Bahmcloud
---

View File

@@ -1,47 +1,36 @@
import logging
import requests
import voluptuous as vol
from homeassistant.helpers import config_validation as cv
async def handle_send_message(call: ServiceCall):
message = call.data.get("message")
recipient = call.data.get("recipient")
use_manual = call.data.get("use_manual_number", False)
target_number = call.data.get("number")
_LOGGER = logging.getLogger(__name__)
entries = hass.config_entries.async_entries(DOMAIN)
targets = []
DOMAIN = "whatsapp_bridge_custom"
# Logik-Prüfung
if use_manual and target_number:
# Fall A: Manuelle Nummer
targets.append(target_number)
elif recipient == "all_accounts":
# Fall B: Rundruf
for e in entries:
targets.append(e.data.get(CONF_PHONE_NUMBER))
elif recipient:
# Fall C: Spezifisches Profil (Recipient Name)
for e in entries:
if e.title.lower() == recipient.lower():
targets.append(e.data.get(CONF_PHONE_NUMBER))
# Definition der Service-Parameter
SERVICE_SEND_MESSAGE = "send_message"
ATTR_NUMBER = "number"
ATTR_MESSAGE = "message"
SERVICE_SCHEMA = vol.Schema({
vol.Required(ATTR_NUMBER): cv.string,
vol.Required(ATTR_MESSAGE): cv.string,
})
async def async_setup(hass, config):
"""Set up the WhatsApp Bridge integration."""
def send_whatsapp_msg(call):
"""Dienst-Funktion: Nachricht an das Add-on senden."""
number = call.data.get(ATTR_NUMBER)
message = call.data.get(ATTR_MESSAGE)
# Die interne URL zum Add-on (standardmäßig local-whatsapp-bridge)
# Port 3000 haben wir im Dockerfile definiert
# Senden (wie gehabt)
for num in targets:
url = "http://866fd2eb-whatsapp-bridge:3000/send"
try:
response = requests.post(url, json={
"number": number,
await hass.async_add_executor_job(
lambda: requests.post(url, json={
"number": num,
"message": message
}, timeout=10)
if response.status_code != 200:
_LOGGER.error("Fehler beim Senden: %s", response.text)
except Exception as e:
_LOGGER.error("Verbindung zum Add-on fehlgeschlagen: %s", str(e))
hass.services.async_register(
DOMAIN, SERVICE_SEND_MESSAGE, send_whatsapp_msg, schema=SERVICE_SCHEMA
)
return True
_LOGGER.info("WhatsApp sent to %s", num)
except Exception as e:
_LOGGER.error("Error sending to %s: %s", num, str(e))

View File

@@ -0,0 +1,25 @@
from homeassistant import config_entries
import voluptuous as vol
from .const import DOMAIN, CONF_PHONE_NUMBER, CONF_ACCOUNT_NAME
class WhatsAppBridgeConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
"""Handle a config flow for WhatsApp Bridge."""
VERSION = 1
async def async_step_user(self, user_input=None):
"""First step when adding the integration via UI."""
errors = {}
if user_input is not None:
return self.async_create_entry(
title=user_input[CONF_ACCOUNT_NAME],
data=user_input
)
return self.async_show_form(
step_id="user",
data_schema=vol.Schema({
vol.Required(CONF_ACCOUNT_NAME, default="John Doe"): str,
vol.Required(CONF_PHONE_NUMBER, default="491701234567"): str,
}),
errors=errors,
)

View File

@@ -0,0 +1,3 @@
DOMAIN = "whatsapp_bridge_integration"
CONF_PHONE_NUMBER = "phone_number"
CONF_ACCOUNT_NAME = "account_name"

View File

@@ -4,6 +4,7 @@
"documentation": "https://git.bahmcloud.de/bahmcloud/Whatsapp-Bridge-Integration",
"dependencies": [],
"codeowners": ["@bahmcloud"],
"version": "0.1.0",
"iot_class": "local_polling"
"version": "0.1.3",
"iot_class": "local_polling",
"config_flow": true
}

View File

@@ -0,0 +1,33 @@
send_message:
name: Send Message
description: Sends a WhatsApp message via the Bahmcloud Bridge.
fields:
recipient:
name: Recipient
description: Select a saved profile or choose "Broadcast to all".
required: true
selector:
select:
options:
- label: "Broadcast to all"
value: "all_accounts"
# Dieser Teil sorgt dafür, dass HA die Namen deiner Accounts anzeigt
custom_value: true
message:
name: Message
description: The content of your WhatsApp message.
required: true
selector:
text:
multiline: true
use_manual_number:
name: Use Manual Number
description: Enable this to ignore the recipient and use the number field below.
default: false
selector:
boolean:
number:
name: Manual Number
description: "Direct phone number (e.g., 491701234567)."
selector:
text: