Skip to content

Commit

Permalink
Refactor SMS API to support multiple recipients per message
Browse files Browse the repository at this point in the history
Updated the `_contact_iap` method to handle messages with multiple recipient numbers. This change simplifies the response handling logic, improving support for bulk SMS sending while maintaining error handling for each individual recipient.
  • Loading branch information
dhongu committed Feb 4, 2025
1 parent 49f21ff commit 3c3eb02
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions deltatech_sms/models/sms_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,13 @@
class SmsApi(BaseSmsApi):
def _contact_iap(self, local_endpoint, params, timeout=15):
account = self.env["iap.account"].get("sms")

res = []

for message in params["messages"]:
res_value = {"state": "success", "res_id": message["res_id"]}

response = account.sudo().send_sms(message["number"], message["content"])

if response["status"] != 200:
res_value["state"] = "server_error"
res_value["error"] = response["message"]

res += [res_value]

for number in message["numbers"]:
res_value = {"state": "success"}
response = account.sudo().send_sms(number["number"], message["content"])
if response["status"] != 200:
res_value["state"] = "server_error"
res_value["error"] = response["message"]
res += [res_value]
return res

0 comments on commit 3c3eb02

Please sign in to comment.