示例#1
0
 def set_init_data(self, jsonData):
     user_phone = helpers.fetch_by_key("urn", jsonData["contact"])
     self.system_phone = helpers.fetch_by_key("address",
                                              jsonData["channel"])
     self.user_phone = helpers.sanitize_phone_string(user_phone)
     self.flow_run_uuid = helpers.fetch_by_key(
         "run_uuid", jsonData
     )  # TODO: need to remove this once every flow has flow_run_details variable in webhook
     self.handle_flow_run_details(jsonData)
 def set_init_data(self, jsonData):
     user_phone = helpers.fetch_by_key("urn", jsonData["contact"])
     self.user_phone = helpers.sanitize_phone_string(user_phone)
     flow_run_uuid = helpers.fetch_by_key(
         "run_uuid", jsonData
     )  # Need to remove once we are done with making changes in webhooks
     if "flow_run_details" in jsonData:
         flow_run_uuid = helpers.fetch_by_key("uuid", jsonData["flow_run_details"])
     call_log_details = models.CallLog.query.get_by_flow_run_uuid(flow_run_uuid)
     self.call_log_id = call_log_details.id
示例#3
0
 def init_data(self, jsonData):
     user_phone = helpers.fetch_by_key("urn", jsonData["contact"])
     self.user_phone = helpers.sanitize_phone_string(user_phone)
     self.user_data = helpers.get_user_by_phone(self.user_phone)
     self.registration_data = helpers.get_registrant_by_phone(self.user_phone)
     self.flow_run_uuid = helpers.fetch_by_key(
         "run_uuid", jsonData
     )  # Need to remove once we are done with making changes in webhooks
     if "flow_run_details" in jsonData:
         self.flow_run_uuid = helpers.fetch_by_key(
             "uuid", jsonData["flow_run_details"]
         )
示例#4
0
    def create_call_logs(self, jsonData):
        try:
            registration_data = models.Registration.query.get_by_phone(
                self.user_phone)
            user_data = models.User.query.get_by_phone(self.user_phone)
            parent_flow_data = self.handle_parent_flow(jsonData)
            flow_name = None
            if "flow" in jsonData and jsonData["flow"] is not None:
                flow_name = helpers.fetch_by_key("name", jsonData["flow"])

            content_id = None
            if "content_id" in jsonData:
                content_id = (jsonData["content_id"], )
                content_data = models.Content.query.get(content_id)
                if not content_data:
                    """If the content id is not available in the system, it will throw the error.
                    Mark it as None
                    """
                    content_id = None
                    print("The Content id is not valid")

            new_call_log = models.CallLog(
                flow_run_uuid=self.flow_run_uuid,
                flow_run_created_on=self.flow_run_created_on,
                call_type=self.fetch_call_type(),
                scheduled_by=self.fetch_call_scheduled_by(),
                user_phone_number=self.user_phone,
                system_phone_number=helpers.sanitize_phone_string(
                    self.system_phone),
                registration_id=registration_data.id
                if registration_data else None,
                user_id=user_data.id if user_data else None,
                call_category=self.call_category,
                parent_flow_name=parent_flow_data["parent_flow_name"],
                parent_flow_run_uuid=parent_flow_data["parent_flow_run_uuid"],
                content_id=content_id,
                flow_name=flow_name,
                flow_category=jsonData["flow_category"]
                if "flow_category" in jsonData else self.flow_category,
                created_on=jsonData["log_created_on"] if jsonData.get(
                    "log_created_on", None) else datetime.utcnow(),
            )
            helpers.save(new_call_log)
            self.call_log = new_call_log
        except:
            # Need to log this
            return "Failed to create call log"
示例#5
0
 def set_init_data(self, jsonData):
     self.content_id = jsonData["content_id"]
     user_phone = helpers.fetch_by_key("urn", jsonData["contact"])
     self.user_phone = helpers.sanitize_phone_string(user_phone)
示例#6
0
 def set_init_data(self, jsonData):
     user_phone = helpers.fetch_by_key("urn", jsonData["contact"])
     self.user_phone = helpers.sanitize_phone_string(user_phone)
     user = models.User.query.get_by_phone(self.user_phone)
     self.user_id = user.id