Skip to content

Commit

Permalink
messageservice upd
Browse files Browse the repository at this point in the history
  • Loading branch information
vaestvita committed Oct 11, 2024
1 parent 1e4b1c4 commit 81791e8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
3 changes: 2 additions & 1 deletion thoth/bitrix/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ def register_connector(appinstance: AppInstance, api_key: str):
# Регистрация SMS-провайдера
def messageservice_add(appinstance, phone, line, api_key, service):
url = appinstance.app.site
filtered_text = ''.join(filter(str.isalnum, phone))
payload = {
"CODE": f"THOTH_{phone}_{line}",
"CODE": f"THOTH_{filtered_text}_{line}",
"NAME": f"THOTH ({phone})",
"TYPE": "SMS",
"HANDLER": f"https://{url}/api/bitrix/sms/?api-key={api_key}&service={service}",
Expand Down
14 changes: 11 additions & 3 deletions thoth/waba/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,21 @@ def save_model(self, request, obj, form, change):
return

api_key = owner.auth_token.key
messageservice_add(obj.app_instance, obj.phone, obj.line.line_id, api_key, 'waba')
resp = messageservice_add(obj.app_instance, obj.phone, obj.line.line_id, api_key, 'waba')
if 'error' in resp:
obj.sms_service = False
obj.save()
messages.error(request, resp)

elif not obj.sms_service and obj.old_sms_service:
call_method(
phone = ''.join(filter(str.isalnum, obj.phone))
resp = call_method(
obj.app_instance,
"messageservice.sender.delete",
{"CODE": f"THOTH_{obj.phone}_{obj.line.line_id}"},
{"CODE": f"THOTH_{phone}_{obj.line.line_id}"},
)
if 'error' in resp:
messages.error(request, resp)

obj.old_sms_service = obj.sms_service
obj.save()

0 comments on commit 81791e8

Please sign in to comment.