Skip to content

Commit dc4b536

Browse files
committed
Address more Phillbot code review comments
1 parent a21baa5 commit dc4b536

3 files changed

Lines changed: 19 additions & 9 deletions

File tree

whatsapp/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Configure the integration within Autohive using platform authentication for What
3535
- **Inputs:**
3636
- `to` (required): Recipient's phone number in E.164 format (e.g., +1234567890)
3737
- `message` (required): Text content of the message to send
38+
- `phone_number_id` (required): The Phone Number ID associated with the WhatsApp Business account
3839
- **Outputs:**
3940
- `message_id`: Unique WhatsApp message identifier if successful
4041
- `success`: Boolean indicating if the message was sent successfully
@@ -46,6 +47,7 @@ Configure the integration within Autohive using platform authentication for What
4647
- **Inputs:**
4748
- `to` (required): Recipient's phone number in E.164 format
4849
- `template_name` (required): Name of the approved message template
50+
- `phone_number_id` (required): The Phone Number ID associated with the WhatsApp Business account
4951
- `language_code` (optional): Template language code (default: "en")
5052
- `parameters` (optional): Array of string parameters for template substitution
5153
- **Outputs:**
@@ -60,6 +62,7 @@ Configure the integration within Autohive using platform authentication for What
6062
- `to` (required): Recipient's phone number in E.164 format
6163
- `media_type` (required): Media type - "image", "document", "audio", or "video"
6264
- `media_url` (required): HTTPS URL of the media content to send
65+
- `phone_number_id` (required): The Phone Number ID associated with the WhatsApp Business account
6366
- `caption` (optional): Text caption for the media (images, videos, documents)
6467
- `filename` (optional): Custom filename for document type media
6568
- **Outputs:**
@@ -89,7 +92,8 @@ Configure the integration within Autohive using platform authentication for What
8992
```json
9093
{
9194
"to": "+1234567890",
92-
"message": "Welcome to our service! Thank you for signing up."
95+
"message": "Welcome to our service! Thank you for signing up.",
96+
"phone_number_id": "123456789012345"
9397
}
9498
```
9599

@@ -99,6 +103,7 @@ Configure the integration within Autohive using platform authentication for What
99103
{
100104
"to": "+1234567890",
101105
"template_name": "customer_welcome",
106+
"phone_number_id": "123456789012345",
102107
"language_code": "en",
103108
"parameters": ["John Doe", "Premium"]
104109
}
@@ -111,6 +116,7 @@ Configure the integration within Autohive using platform authentication for What
111116
"to": "+1234567890",
112117
"media_type": "document",
113118
"media_url": "https://yourdomain.com/invoices/invoice-123.pdf",
119+
"phone_number_id": "123456789012345",
114120
"filename": "Invoice-123.pdf",
115121
"caption": "Your invoice for Order #123"
116122
}

whatsapp/tests/test_whatsapp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ async def test_send_media_message():
5454
inputs = {
5555
"to": TEST_RECIPIENT_PHONE,
5656
"media_type": "image",
57-
"media_url": "https://cdn.prod.website-files.com/67f5c4ac73ceeeb74774a8ee/691b8e27af0bfbc9290f345d_bee-left.webp",
57+
"media_url": "https://fastly.picsum.photos/id/184/640/320.jpg?hmac=Zu0guI3nKOcrdKw3FDso83cEaPL-6BltxGz8mrSEErg",
5858
"caption": "Test image from WhatsApp integration",
5959
"phone_number_id": PHONE_NUMBER_ID
6060
}

whatsapp/whatsapp.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
)
44
from typing import Dict, Any
55
import re
6+
from urllib.parse import urlparse
67

78
whatsapp = Integration.load()
89

@@ -21,13 +22,16 @@ def get_whatsapp_creds(auth: Dict[str, Any]) -> Dict[str, str]:
2122
}
2223

2324
def validate_phone_number(phone: str) -> bool:
24-
"""Validate that the phone number is in E.164 format."""
25-
pattern = r'^\+[1-9]\d{1,14}$'
25+
"""Validate that the phone number is in E.164 format (with or without + prefix)."""
26+
pattern = r'^\+?[1-9]\d{1,14}$'
2627
return bool(re.match(pattern, phone))
2728

2829
def validate_media_url(url: str) -> bool:
29-
"""Validate that the media URL is a valid HTTPS URL."""
30-
return url.startswith("https://")
30+
try:
31+
u = urlparse(url)
32+
return u.scheme == "https" and bool(u.netloc)
33+
except Exception:
34+
return False
3135

3236
def validate_phone_number_id(phone_number_id: str) -> bool:
3337
"""Validate that the phone number ID is a numeric string."""
@@ -58,7 +62,7 @@ async def execute(self, inputs: Dict[str, Any], context: ExecutionContext):
5862
return ActionResult(data={
5963
"message_id": None,
6064
"success": False,
61-
"error": "Invalid phone number format. Use format: +1234567890"
65+
"error": "Invalid phone number format. Use format: +1234567890 or 1234567890"
6266
})
6367

6468
try:
@@ -129,7 +133,7 @@ async def execute(self, inputs: Dict[str, Any], context: ExecutionContext):
129133
return ActionResult(data={
130134
"message_id": None,
131135
"success": False,
132-
"error": "Invalid phone number format. Use format: +1234567890"
136+
"error": "Invalid phone number format. Use format: +1234567890 or 1234567890"
133137
})
134138

135139
try:
@@ -211,7 +215,7 @@ async def execute(self, inputs: Dict[str, Any], context: ExecutionContext):
211215
return ActionResult(data={
212216
"message_id": None,
213217
"success": False,
214-
"error": "Invalid phone number format. Use format: +1234567890"
218+
"error": "Invalid phone number format. Use format: +1234567890 or 1234567890"
215219
})
216220

217221
# Validate media URL

0 commit comments

Comments
 (0)