From fe0c6afa35d00e04e91b7f4fad2d1e6c94f6e381 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=95=8A=E7=88=86?= <157203576+abao168899@users.noreply.github.com> Date: Mon, 14 Oct 2024 19:52:28 +0800 Subject: [PATCH] Update Sms77api.py Send SMS in bulk --- src/sms77api/Sms77api.py | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/sms77api/Sms77api.py b/src/sms77api/Sms77api.py index d902f12..50237a2 100644 --- a/src/sms77api/Sms77api.py +++ b/src/sms77api/Sms77api.py @@ -10,19 +10,17 @@ from sms77api.classes.Subaccounts import SubaccountsAction -def expect_json(endpoint: str, params: dict) -> bool: - if endpoint in [Endpoint.BALANCE.value, Endpoint.VOICE.value]: - return False - if 'json' not in params: - return False - if params['json'] is not True and params['json'] != 1: - return False - return True - - -def local_params(locals_: dict) -> dict: - del locals_['self'] - return locals_ +# 在 src/sms77api/Sms77api.py 文件中添加 bulk_sms 方法 +def bulk_sms(self, messages: list, params: dict = {}): + results = [] + for message in messages: + to, text = message.get('to'), message.get('text') + if to and text: + result = self.sms(to, text, params) + results.append(result) + else: + raise ValueError("Each message must have 'to' and 'text' fields.") + return results class Sms77api: