33import json
44import re
55
6- from typings import Donation , Form , Payload , Pressure , Plip
6+ from typings import Donation , Form , Payload , Pressure , Plip , BaseAction
77from utils import only_digits , get_field , find_by_ddd
88
99
@@ -151,6 +151,19 @@ def plip(payload: Plip):
151151 )
152152 return clean_response (item )
153153
154+ def widget_action (payload : BaseAction ):
155+ item = {
156+ "name" : payload .first_name + " " + payload .last_name ,
157+ "email" : payload .email ,
158+ "phone" : normalize_phone (payload .phone_number ) if payload .phone_number else None ,
159+ "metadata" : payload .custom_fields
160+ }
161+
162+ if item ["phone" ]:
163+ item ["region" ] = find_by_ddd (item ["phone" ])
164+
165+ return clean_response (item )
166+
154167
155168def to_payload (data : Payload ):
156169 """to_payload"""
@@ -174,9 +187,14 @@ def to_payload(data: Payload):
174187 response = plip (payload = payload )
175188 response ["action" ] = "plip"
176189
190+ else :
191+ # Ação padronizada
192+ response = widget_action (payload = payload )
193+ response ["action" ] = payload .kind
194+
177195 response ["widget_id" ] = payload .widget_id
178196 response ["mobilization_id" ] = payload .mobilization_id
179- response ["community_id" ] = payload .cached_community_id
197+ response ["community_id" ] = payload .cached_community_id or payload . community_id
180198 response ["action_id" ] = payload .id
181199 response ["action_date" ] = payload .created_at
182200
0 commit comments