Esempio n. 1
0
def webhook_delivered(request, webhook_id):

    print("In webhook_delivered")
    """
    Webhook function to notify user about update in component
    """

    urllib.parse.unquote(request.body.decode("utf-8"))
    params_dict = urllib.parse.parse_qsl(request.body)
    params = dict(params_dict)

    #Extracting necessary data
    recipient = params[b'recipient'].decode('utf-8')

    # Fetching yellowant object
    try:
        yellow_obj = YellowUserToken.objects.get(webhook_id=webhook_id)
        print(yellow_obj)
        access_token = yellow_obj.yellowant_token
        print(access_token)
        integration_id = yellow_obj.yellowant_integration_id
        service_application = str(integration_id)
        print(service_application)

        # Creating message object for webhook message
        webhook_message = MessageClass()
        webhook_message.message_text = "Mail delivered to " + str(recipient)

        attachment = MessageAttachmentsClass()
        attachment.title = "Mail Stats upto last 1 month"

        button_get_components = MessageButtonsClass()
        button_get_components.name = "1"
        button_get_components.value = "1"
        button_get_components.text = "Get all stats"
        button_get_components.command = {
            "service_application": service_application,
            "function_name": 'get_stats',
            "data": {}
        }

        attachment.attach_button(button_get_components)
        webhook_message.data = {"recipient_email_id": recipient}
        webhook_message.attach(attachment)
        #print(integration_id)

        # Creating yellowant object
        yellowant_user_integration_object = YellowAnt(
            access_token=access_token)

        # Sending webhook message to user
        send_message = yellowant_user_integration_object.create_webhook_message(
            requester_application=integration_id,
            webhook_name="notify_delivered",
            **webhook_message.get_dict())

        return HttpResponse("OK", status=200)

    except YellowUserToken.DoesNotExist:
        return HttpResponse("Not Authorized", status=403)
Esempio n. 2
0
def responsewebhook(request, hash_str=""):
    """Whenever a new response is completed the user gets notified"""
    try:
        ya_obj = YellowUserToken.objects.get(webhook_id=hash_str)
    except YellowUserToken.DoesNotExist:
        return HttpResponse("Not Authorized", status=403)

    try:
        data_obj = json.loads(request.body)
        print(data_obj)
        notification_type = data_obj['event_type']
        if notification_type == "response_completed":
            message = MessageClass()
            message.message_text = "New survey response completed"
            message.data = data_obj
            yauser_integration_object = YellowAnt(
                access_token=ya_obj.yellowant_token)

            send_message = yauser_integration_object.create_webhook_message(\
            requester_application=ya_obj.yellowant_intergration_id, \
            webhook_name="response_completed", **message.get_dict())

        return HttpResponse("webhook_receiver/webhook_receiver/")
    except Exception as e:
        print(str(e))
        return HttpResponse("Empty body")
Esempio n. 3
0
def update_incident(request,webhook_id):
    print("In update_incident")
    """
    Webhook function to notify user about update in incident
    """

    # Extracting necessary data
    data = (request.body.decode('utf-8'))
    response_json = json.loads(data)

    page_id = response_json['page']['id']
    unsubscribe = response_json['meta']['unsubscribe']
    incident_id = response_json['incident']['id']
    name = response_json['incident']['name']

    try:
        # Fetching yellowant object
        yellow_obj = YellowUserToken.objects.get(webhook_id=webhook_id)
        print(yellow_obj)
        access_token = yellow_obj.yellowant_token
        print(access_token)
        integration_id = yellow_obj.yellowant_integration_id
        service_application = str(integration_id)
        print(service_application)

        # Creating message object for webhook message

        webhook_message = MessageClass()
        webhook_message.message_text = "Updates in incident with Id : " + str(incident_id) + "\nName : " + str(name)
        attachment = MessageAttachmentsClass()
        attachment.title = "Incident operations"

        button_get_incidents = MessageButtonsClass()
        button_get_incidents.name = "1"
        button_get_incidents.value = "1"
        button_get_incidents.text = "Get all incidents"
        button_get_incidents.command = {
            "service_application": service_application,
            "function_name": 'all_incidents',
            "data": {
            'page_id': page_id
                }
            }

        attachment.attach_button(button_get_incidents)
        webhook_message.data = {"page_id": page_id}
        webhook_message.attach(attachment)
        #print(integration_id)

        # Creating yellowant object
        yellowant_user_integration_object = YellowAnt(access_token=access_token)

        # Sending webhook message to user
        send_message = yellowant_user_integration_object.create_webhook_message(
        requester_application=integration_id,
        webhook_name="incident_updates_webhook", **webhook_message.get_dict())
        return HttpResponse("OK", status=200)

    except YellowUserToken.DoesNotExist:
        return HttpResponse("Not Authorized", status=403)
Esempio n. 4
0
def add_new_pipeline(request, webhook_id):
    """
            Webhook function to notify user about newly added pipeline
    """

    data = request.body
    data_string = data.decode('utf-8')
    data_json = json.loads(data_string)

    name = data_json["current"]['name']
    add_time = data_json["current"]['add_time']
    url_tile = data_json["current"]['url_title']
    order = data_json["current"]['order_nr']

    # Fetching yellowant object
    yellow_obj = YellowUserToken.objects.get(webhook_id=webhook_id)
    access_token = yellow_obj.yellowant_token
    integration_id = yellow_obj.yellowant_integration_id
    service_application = str(integration_id)

    # Creating message object for webhook message
    webhook_message = MessageClass()
    webhook_message.message_text = "New pipeline created." + "\n" + "The pipeline name : " + str(
        name)
    attachment = MessageAttachmentsClass()

    button_get_pipeline = MessageButtonsClass()
    button_get_pipeline.name = "1"
    button_get_pipeline.value = "1"
    button_get_pipeline.text = "Get all pipelines"
    button_get_pipeline.command = {
        "service_application": service_application,
        "function_name": 'list_pipelines',
        "data": {
            'data': "test",
        }
    }

    attachment.attach_button(button_get_pipeline)
    webhook_message.attach(attachment)
    # print(integration_id)
    webhook_message.data = {
        "Add Time": add_time,
        "Url title": url_tile,
        "Name": name,
        "Order": order,
    }

    # Creating yellowant object
    yellowant_user_integration_object = YellowAnt(access_token=access_token)

    # Sending webhook message to user
    send_message = yellowant_user_integration_object.create_webhook_message(
        requester_application=integration_id,
        webhook_name="new_pipeline",
        **webhook_message.get_dict())
    return HttpResponse("OK", status=200)
Esempio n. 5
0
    def run(self):
        """Method which runs when the thread is started"""
        global GROUP_NAME, VM_NAME, USERNAME, PASSWORD

        message = MessageClass()
        credentials, subscription_id = get_credentials(self.user_integration)
        compute_client = ComputeManagementClient(credentials, subscription_id)
        network_client = NetworkManagementClient(credentials, subscription_id)
        GROUP_NAME = self.args.get("Resource-Group")
        VM_NAME = self.args.get("VM-Name")
        NIC_NAME = self.args.get("nic_name")
        IP_CONFIG_NAME = self.args.get("ipconfig_name")
        USERNAME = self.args.get("username")
        PASSWORD = self.args.get("password")
        VNET_NAME = self.args.get("vnet_name")
        SUBNET_NAME = self.args.get("subnet_name")
        LOCATION = self.args.get("location")

        try:
            # Create a NIC
            nic = create_nic(network_client, VNET_NAME, SUBNET_NAME,
                             IP_CONFIG_NAME, NIC_NAME)

            #############
            # VM Sample #
            #############

            # Create Linux VM
            print('\nCreating Linux Virtual Machine')
            vm_parameters = create_vm_parameters(nic.id, VM_REFERENCE['linux'],
                                                 VM_NAME, USERNAME, PASSWORD,
                                                 LOCATION)
            async_vm_creation = compute_client.virtual_machines.create_or_update(
                GROUP_NAME, VM_NAME, vm_parameters)
            # async_vm_creation.wait()
            message.message_text = "You are Virtual Machine is being created"

        except CloudError:
            print('A VM operation failed:', traceback.format_exc(), sep='\n')
            message.message_text = "There was an error.Please try again"

        else:
            webhook_message = MessageClass()
            webhook_message.message_text = "VM created successfully"
            attachment = MessageAttachmentsClass()
            attachment.title = VM_NAME

            webhook_message.attach(attachment)
            yellowant_user_integration_object = YellowAnt(
                access_token=self.user_integration.yellowant_integration_token)
            yellowant_user_integration_object.create_webhook_message(
                requester_application=self.user_integration.
                yellowant_integration_id,
                webhook_name="start_vm_webhook",
                **webhook_message.get_dict())
            print('All example operations completed successfully!')
Esempio n. 6
0
def incident_resolved(request, webhook_id):
    #
    data = request.body
    data_string = data.decode('utf-8')
    data_json = json.loads(data_string)

    name = data_json['display_name']
    entity_id = data_json['entity_id']
    incident_number = data_json['incident_number']
    # Fetching yellowant object
    yellow_obj = YellowUserToken.objects.get(webhook_id=webhook_id)
    access_token = yellow_obj.yellowant_token
    integration_id = yellow_obj.yellowant_integration_id
    service_application = str(integration_id)

    # Creating message object for webhook message
    webhook_message = MessageClass()
    webhook_message.message_text = "Incident Resolved\n The entity ID : " + str(entity_id) \
                                   + "\nThe Incident Number : " + str(incident_number)
    attachment = MessageAttachmentsClass()
    attachment.title = "Incident Operations"

    button_get_incidents = MessageButtonsClass()
    button_get_incidents.name = "1"
    button_get_incidents.value = "1"
    button_get_incidents.text = "Get all incidents"
    button_get_incidents.command = {
        "service_application": service_application,
        "function_name": 'list_incidents',
        "data": {
            'data': "test",
        }
    }

    attachment.attach_button(button_get_incidents)
    webhook_message.attach(attachment)
    # print(integration_id)
    webhook_message.data = {
        "Display Name": name,
        "Entity ID": entity_id,
        "Incident Number": incident_number,
    }

    # Creating yellowant object
    yellowant_user_integration_object = YellowAnt(access_token=access_token)

    # Sending webhook message to user
    yellowant_user_integration_object.create_webhook_message(
        requester_application=integration_id,
        webhook_name="new_incident_resolved",
        **webhook_message.get_dict())

    return HttpResponse("OK", status=200)
Esempio n. 7
0
def add_new_invoice(request, id):
    """
            Webhook function to notify user about newly created invoice
    """
    print(request.body)
    invoice_id = request.POST['ID']
    contact_email = request.POST['Email']
    total = request.POST['Total']

    # Fetching yellowant object
    yellow_obj = YellowUserToken.objects.get(webhook_id=id)
    access_token = yellow_obj.yellowant_token
    integration_id = yellow_obj.yellowant_integration_id
    # service_application = str(integration_id)

    # Creating message object for webhook message
    webhook_message = MessageClass()
    webhook_message.message_text = "New invoice added"

    attachment = MessageAttachmentsClass()

    field = AttachmentFieldsClass()
    field.title = "Invoice ID"
    field.value = invoice_id
    attachment.attach_field(field)

    field1 = AttachmentFieldsClass()
    field1.title = "Total"
    field1.value = total
    attachment.attach_field(field1)

    field2 = AttachmentFieldsClass()
    field2.title = "Contact Email"
    field2.value = contact_email
    attachment.attach_field(field2)

    webhook_message.attach(attachment)
    # print(integration_id)
    webhook_message.data = {
        "Invoice ID": invoice_id,
        "Total": total,
        "Contact Email": contact_email,
    }

    # Creating yellowant object
    yellowant_user_integration_object = YellowAnt(access_token=access_token)

    # Sending webhook message to user
    yellowant_user_integration_object.create_webhook_message(
        requester_application=integration_id,
        webhook_name="new_invoice",
        **webhook_message.get_dict())
    return HttpResponse("OK", status=200)
Esempio n. 8
0
def accept(args,user_integration):
    """
    Function to accept the invitation from another player.
    """
    opponent_user_integration = args.get("user_int")

    state = str(uuid.uuid4())

    opponent_object = UserIntegration.objects.get(yellowant_integration_id=opponent_user_integration)
    opponent_object.playing_state = state
    player_object = UserIntegration.objects.get(yellowant_integration_id=user_integration.yellowant_integration_id)
    player_object.playing_state = state

    player_object.opponent_integration_id = opponent_object.yellowant_integration_id
    opponent_object.opponent_integration_id = player_object.yellowant_integration_id

    player_object.board_state = INITIAL_BOARD + INITIAL_BOARD_REST
    opponent_object.board_state = INITIAL_BOARD + INITIAL_BOARD_REST

    player_object.save()
    opponent_object.save()


    webhook_message = MessageClass()
    webhook_message.message_text = "Chess Invite"
    attachment = MessageAttachmentsClass()
    field1 = AttachmentFieldsClass()
    field1.title = "Your Chess Invite has been accepted by"
    field1.value = player_object.yellowant_team_subdomain

    button = MessageButtonsClass()
    button.text = "Start Game"
    button.value = "Start Game"
    button.name = "Start Game"
    button.command = {
                      "service_application" : str(opponent_object.yellowant_integration_id),
                      "function_name" : "startgameplayer",
                      "data" : {"user_int": player_object.yellowant_integration_id},
                      "inputs" :  ["Color"]
                     }
    attachment.attach_button(button)
    attachment.attach_field(field1)
    webhook_message.attach(attachment)

    access_token = opponent_object.yellowant_integration_token
    yellowant_user_integration_object = YellowAnt(access_token=access_token)

    send_message = yellowant_user_integration_object.create_webhook_message(
        requester_application=opponent_object.yellowant_integration_id,
        webhook_name="webhook", **webhook_message.get_dict())

    m = MessageClass()
    return m
Esempio n. 9
0
def employee_created(request, id):

    print('Inside employee created')
    name = request.POST['name']
    contact_id = request.POST['id']
    last_name = request.POST['last_name']
    email = request.POST['email']

    yellow_obj = UserIntegration.objects.get(webhook_id=id)
    access_token = yellow_obj.yellowant_integration_token
    integration_id = yellow_obj.yellowant_integration_id
    service_application = str(integration_id)

    # Creating message object for webhook message
    webhook_message = MessageClass()
    webhook_message.message_text = "New Employee added"
    attachment = MessageAttachmentsClass()

    field = AttachmentFieldsClass()
    field.title = "Name"
    field.value = name + " " + last_name

    attachment.attach_field(field)

    field1 = AttachmentFieldsClass()
    field1.title = "Email ID"
    field1.value = email

    attachment.attach_field(field1)

    # print(integration_id)
    webhook_message.data = {
        "Name": name,
        "ID": contact_id,
        "Email": email,
        "LastName": last_name
    }
    webhook_message.attach(attachment)
    # Creating yellowant object
    yellowant_user_integration_object = YellowAnt(access_token=access_token)

    # Sending webhook message to user
    send_message = yellowant_user_integration_object.create_webhook_message(
        requester_application=service_application,
        webhook_name="createemployeewebhook",
        **webhook_message.get_dict())
    return HttpResponse("OK", status=200)
Esempio n. 10
0
def webhooks(request, id=None):
    #print(request.post.data)
    # print(type(request))
    # print((request.body))
    try:
        body = json.loads(json.dumps((request.body.decode("utf-8"))))

        # print("Body is")
        # print(body)
        # print(json.loads(body))
        body = json.loads(body)
    except:
        return HttpResponse("Failed", status=404)

    # print(body['sys_id'])
    User = UserIntegration.objects.get(webhook_id=id)
    service_application = str(User.yellowant_integration_id)
    access_token = User.yellowant_integration_token

    #######    STARTING WEB HOOK PART
    webhook_message = MessageClass()
    webhook_message.message_text = "Incident" + " " + body['state']
    attachment = MessageAttachmentsClass()
    field1 = AttachmentFieldsClass()
    field1.title = "Incident Name"
    field1.value = body['number']
    attachment.attach_field(field1)
    webhook_message.attach(attachment)

    attachment = MessageAttachmentsClass()
    field1 = AttachmentFieldsClass()
    field1.title = "Incident Description"
    field1.value = body['description']
    attachment.attach_field(field1)
    webhook_message.attach(attachment)

    # Creating yellowant object
    yellowant_user_integration_object = YellowAnt(access_token=access_token)

    # Sending webhook message to user
    send_message = yellowant_user_integration_object.create_webhook_message(
        requester_application=User.yellowant_integration_id,
        webhook_name="webhook",
        **webhook_message.get_dict())
    return HttpResponse("OK", status=200)
Esempio n. 11
0
def playAgainst(args,user_integration):
    """
    Function which sends the invite to other players to play chess.
    """
    opponent_id = args.get("yellowant_user_id")
    opponent_object = UserIntegration.objects.get(yellowant_integration_id=opponent_id)
    player_object = UserIntegration.objects.get(yellowant_integration_id=user_integration.yellowant_integration_id)

    webhook_message = MessageClass()
    webhook_message.message_text = "Chess Invite"
    attachment = MessageAttachmentsClass()
    field1 = AttachmentFieldsClass()
    field1.title = "You have been invited to play chess with "
    field1.value = player_object.yellowant_team_subdomain

    button = MessageButtonsClass()
    button.text = "Accept Invitation"
    button.value = "Accept Invitation"
    button.name = "Accept Invitation"
    button.command = {
                      "service_application": str(opponent_object.yellowant_integration_id),
                      "function_name": "accept",
                      "data": {"user_int": player_object.yellowant_integration_id }
                     }
    attachment.attach_button(button)
    attachment.attach_field(field1)
    webhook_message.attach(attachment)
    access_token = opponent_object.yellowant_integration_token
    yellowant_user_integration_object = YellowAnt(access_token=access_token)

    print("Printing webhook")
    send_message = yellowant_user_integration_object.create_webhook_message(
        requester_application=opponent_object.yellowant_integration_id,
        webhook_name="webhook", **webhook_message.get_dict())


    m = MessageClass()
    m.message_text = "Waiting for response from opponent"

    return m
Esempio n. 12
0
def add_new_contact(request, id):
    """
            Webhook function to notify user about newly added contact
    """
    # print("in contacts")
    # print(request.body)
    name = request.POST['name']
    contact_id = request.POST['ID']
    email = "-" if request.POST['email'] is None else request.POST['email']
    company_name = request.POST['company_name']

    # Fetching yellowant object
    yellow_obj = YellowUserToken.objects.get(webhook_id=id)
    access_token = yellow_obj.yellowant_token
    integration_id = yellow_obj.yellowant_integration_id
    # service_application = str(integration_id)

    # Creating message object for webhook message
    webhook_message = MessageClass()
    webhook_message.message_text = "New contact added."
    attachment = MessageAttachmentsClass()

    field = AttachmentFieldsClass()
    field.title = "Contact Name"
    field.value = name
    attachment.attach_field(field)

    field1 = AttachmentFieldsClass()
    field1.title = "Contact ID"
    field1.value = contact_id
    attachment.attach_field(field1)

    field2 = AttachmentFieldsClass()
    field2.title = "Company Name"
    field2.value = company_name
    attachment.attach_field(field2)

    field3 = AttachmentFieldsClass()
    field3.title = "Email"
    field3.value = email
    attachment.attach_field(field3)

    webhook_message.attach(attachment)

    # print(integration_id)
    webhook_message.data = {
        "Name": name,
        "ID": contact_id,
        "Email": email,
        "Company Name": company_name
    }

    # Creating yellowant object
    yellowant_user_integration_object = YellowAnt(access_token=access_token)

    # Sending webhook message to user
    yellowant_user_integration_object.create_webhook_message(
        requester_application=integration_id,
        webhook_name="new_contact",
        **webhook_message.get_dict())
    return HttpResponse("OK", status=200)
Esempio n. 13
0
def webhook(request, hash_str=""):
    '''Respond to the webhook verification (GET request) by echoing back the challenge parameter.'''
    print("Inside webhook")

    if request.method == "GET":
        print("Inside webhook validation")
        challenge = request.GET.get('challenge', None)

        if challenge != None:
            return HttpResponse(challenge, status=200)
        else:
            return HttpResponse(status=400)

    else:
        print("In notifications")
        webhook_id = hash_str
        data = (request.body.decode('utf-8'))
        response_json = json.loads(data)
        print(response_json)

        data = {"users": [], "accounts": []}

        try:
            yellow_obj = YellowUserToken.objects.get(webhook_id=webhook_id)
            print(yellow_obj)
            access_token = yellow_obj.yellowant_token
            print(access_token)
            integration_id = yellow_obj.yellowant_integration_id
            service_application = str(integration_id)
            print(service_application)

            # Creating message object for webhook message

            webhook_message = MessageClass()
            webhook_message.message_text = "File/Folder updated !"
            attachment = MessageAttachmentsClass()
            attachment.title = "Updated file/folder details :"

            for i in range(0, len(response_json['list_folder']['accounts'])):
                field1 = AttachmentFieldsClass()
                field1.title = "Id : "
                field1.value = response_json['list_folder']['accounts'][i]
                data["accounts"].append(
                    response_json['list_folder']['accounts'][i])
                attachment.attach_field(field1)

            attachment2 = MessageAttachmentsClass()
            attachment2.title = "User update details :"

            for i in range(0, len(response_json['delta']['users'])):
                field2 = AttachmentFieldsClass()
                field2.title = "Id : "
                field2.value = response_json['delta']['users'][i]
                data["users"].append(response_json['delta']['users'][i])
                attachment2.attach_field(field2)

            button = MessageButtonsClass()
            button.name = "1"
            button.value = "1"
            button.text = "Get all files and folders "
            button.command = {
                "service_application": service_application,
                "function_name": 'get_all_folders',
                "data": {
                    "path": "",
                    "recursive": True,
                    "include_media_info": False,
                    "include_deleted": False,
                    "include_has_explicit_shared_members": False,
                    "include_mounted_folders": True
                }
            }

            attachment.attach_button(button)
            webhook_message.attach(attachment)
            webhook_message.attach(attachment2)
            #print(integration_id)
            print("-----------")
            print(data)
            print("------------")
            webhook_message.data = data
            # Creating yellowant object
            yellowant_user_integration_object = YellowAnt(
                access_token=access_token)

            # Sending webhook message to user
            send_message = yellowant_user_integration_object.create_webhook_message(
                requester_application=integration_id,
                webhook_name="files_folders_update",
                **webhook_message.get_dict())

            return HttpResponse("OK", status=200)

        except YellowUserToken.DoesNotExist:
            return HttpResponse("Not Authorized", status=403)
Esempio n. 14
0
def incident_triggered(request, webhook_id):
    """
        Webhook function to notify user about newly created incident
    """
    # Extracting necessary data
    data = request.body
    data_string = data.decode('utf-8')
    data_json = json.loads(data_string)

    name = data_json['display_name']
    entity_id = data_json['entity_id']
    incident_number = data_json['incident_number']
    # Fetching yellowant object
    yellow_obj = YellowUserToken.objects.get(webhook_id=webhook_id)
    access_token = yellow_obj.yellowant_token
    integration_id = yellow_obj.yellowant_integration_id
    service_application = str(integration_id)

    # Creating message object for webhook message
    webhook_message = MessageClass()
    webhook_message.message_text = "Incident Triggered\n The entity ID : " + str(entity_id)\
                                   + "\nThe Incident Number : " + str(incident_number) +\
                                   "\n Incident message : " + str(name)
    attachment = MessageAttachmentsClass()
    attachment.title = "Incident Operations"

    # button_get_incidents = MessageButtonsClass()
    # button_get_incidents.name = "1"
    # button_get_incidents.value = "1"
    # button_get_incidents.text = "Get all incidents"
    # button_get_incidents.command = {
    #     "service_application": service_application,
    #     "function_name": 'list_incidents',
    #     "data": {
    #         'data': "test",
    #     }
    # }
    #
    # attachment.attach_button(button_get_incidents)

    button_ack_incidents = MessageButtonsClass()
    button_ack_incidents.name = "2"
    button_ack_incidents.value = "2"
    button_ack_incidents.text = "Acknowledge the current incident"
    button_ack_incidents.command = {
        "service_application": service_application,
        "function_name": 'ack_incidents',
        "data": {
            "Incident-Numbers": incident_number,
        },
        "inputs": ["Acknowledgement-Message"]
    }

    attachment.attach_button(button_ack_incidents)

    webhook_message.attach(attachment)
    # print(integration_id)
    webhook_message.data = {
        "Display Name": name,
        "Entity ID": entity_id,
        "Incident Number": incident_number,
    }

    # Creating yellowant object
    yellowant_user_integration_object = YellowAnt(access_token=access_token)

    # Sending webhook message to user
    yellowant_user_integration_object.create_webhook_message(
        requester_application=integration_id,
        webhook_name="new_incident",
        **webhook_message.get_dict())

    return HttpResponse("OK", status=200)
Esempio n. 15
0
def deal_task_add(request, webhook_id):
    """
            Webhook function to notify user about newly added pipeline
    """

    data = request.body.decode('utf-8')
    # print(type(data))
    urllib.parse.unquote(data)
    params_dict = urllib.parse.parse_qsl(data)
    params = dict(params_dict)

    email = params['deal[contact_email]']
    name = params['deal[contact_firstname]'] + " " + params[
        'deal[contact_lastname]']
    type = "Deal Task Added"
    time = params['date_time']
    # Fetching yellowant object
    yellow_obj = UserIntegration.objects.get(webhook_id=webhook_id)
    access_token = yellow_obj.yellowant_integration_token
    integration_id = yellow_obj.yellowant_integration_id
    service_application = str(integration_id)

    # Creating message object for webhook message
    webhook_message = MessageClass()
    attachment = MessageAttachmentsClass()
    webhook_message.message_text = "A new Deal task is added "

    field2 = AttachmentFieldsClass()
    field2.title = "Name"
    field2.value = name
    attachment.attach_field(field2)

    field2 = AttachmentFieldsClass()
    field2.title = "Email"
    field2.value = email
    attachment.attach_field(field2)

    field2 = AttachmentFieldsClass()
    field2.title = "Deal Currency"
    field2.value = params['deal[currency]']
    attachment.attach_field(field2)

    field2 = AttachmentFieldsClass()
    field2.title = "Deal title"
    field2.value = params['deal[title]']
    attachment.attach_field(field2)

    field2 = AttachmentFieldsClass()
    field2.title = "Deal Pipeline title"
    field2.value = params['deal[pipeline_title]']
    attachment.attach_field(field2)

    field2 = AttachmentFieldsClass()
    field2.title = "Deal Stage title"
    field2.value = params['deal[stage_title]']
    attachment.attach_field(field2)

    field2 = AttachmentFieldsClass()
    field2.title = "Deal Note"
    field2.value = params['deal[note]']
    attachment.attach_field(field2)

    field2 = AttachmentFieldsClass()
    field2.title = "Task Note"
    field2.value = params['task[note]']
    attachment.attach_field(field2)

    field2 = AttachmentFieldsClass()
    field2.title = "Deal Value"
    field2.value = params['deal[value]']
    attachment.attach_field(field2)

    # button_get_pipeline = MessageButtonsClass()
    # button_get_pipeline.name = "1"
    # button_get_pipeline.value = "1"
    # button_get_pipeline.text = "Get all pipelines"
    # button_get_pipeline.command = {
    #     "service_application": service_application,
    #     "function_name": 'list_pipelines',
    #     "data": {
    #         'data': "test",
    #     }
    # }

    # attachment.attach_button(button_get_pipeline)
    webhook_message.attach(attachment)
    # print(integration_id)
    webhook_message.data = {
        "Name": name,
        "Email": email,
        "Type": type,
        "Time": time,
    }

    # Creating yellowant object
    yellowant_user_integration_object = YellowAnt(access_token=access_token)

    # Sending webhook message to user
    send_message = yellowant_user_integration_object.create_webhook_message(
        requester_application=integration_id,
        webhook_name="deal-task-add",
        **webhook_message.get_dict())
    return HttpResponse("OK", status=200)
Esempio n. 16
0
def list_added(request, webhook_id):
    """
            Webhook function to notify user about newly added pipeline
    """

    data = request.body.decode('utf-8')
    # print(type(data))
    urllib.parse.unquote(data)
    params_dict = urllib.parse.parse_qsl(data)
    params = dict(params_dict)

    # email = params['contact[email]']
    # name = params['contact[first_name]']+" "+params['contact[last_name]']
    type = "List Added"
    time = params['date_time']
    # Fetching yellowant object
    yellow_obj = UserIntegration.objects.get(webhook_id=webhook_id)
    access_token = yellow_obj.yellowant_integration_token
    integration_id = yellow_obj.yellowant_integration_id
    service_application = str(integration_id)

    # Creating message object for webhook message
    webhook_message = MessageClass()
    attachment = MessageAttachmentsClass()
    webhook_message.message_text = "A new list is created"

    field2 = AttachmentFieldsClass()
    field2.title = "Sender URL"
    field2.value = params['list[sender_state]']
    attachment.attach_field(field2)

    field2 = AttachmentFieldsClass()
    field2.title = "Sender Address 1"
    field2.value = params['list[sender_addr1]']
    attachment.attach_field(field2)

    field2 = AttachmentFieldsClass()
    field2.title = "Sender Address 2"
    field2.value = params['list[sender_addr2]']
    attachment.attach_field(field2)

    field2 = AttachmentFieldsClass()
    field2.title = "Sender Remainder"
    field2.value = params['list[sender_reminder]']
    attachment.attach_field(field2)

    # button_get_pipeline = MessageButtonsClass()
    # button_get_pipeline.name = "1"
    # button_get_pipeline.value = "1"
    # button_get_pipeline.text = "Get all pipelines"
    # button_get_pipeline.command = {
    #     "service_application": service_application,
    #     "function_name": 'list_pipelines',
    #     "data": {
    #         'data': "test",
    #     }
    # }

    # attachment.attach_button(button_get_pipeline)
    webhook_message.attach(attachment)
    # print(integration_id)
    webhook_message.data = {
        # "Name": name,
        # "Email": email,
        "Type": type,
        "Time": time,
    }

    # Creating yellowant object
    yellowant_user_integration_object = YellowAnt(access_token=access_token)

    # Sending webhook message to user
    send_message = yellowant_user_integration_object.create_webhook_message(
        requester_application=integration_id,
        webhook_name="list-added",
        **webhook_message.get_dict())
    return HttpResponse("OK", status=200)
Esempio n. 17
0
def contact_unsubscribe(request, webhook_id):
    """
            Webhook function to notify user about newly added pipeline
    """

    data = request.body.decode('utf-8')
    # print(type(data))
    urllib.parse.unquote(data)
    params_dict = urllib.parse.parse_qsl(data)
    params = dict(params_dict)

    email = params['contact[email]']
    name = params['contact[first_name]'] + " " + params['contact[last_name]']
    type = "Campaign Opened"
    time = params['date_time']
    # Fetching yellowant object
    yellow_obj = UserIntegration.objects.get(webhook_id=webhook_id)
    access_token = yellow_obj.yellowant_integration_token
    integration_id = yellow_obj.yellowant_integration_id
    service_application = str(integration_id)

    # Creating message object for webhook message
    webhook_message = MessageClass()
    attachment = MessageAttachmentsClass()
    webhook_message.message_text = "The Contact has Unsubscribed " + str(name)

    field2 = AttachmentFieldsClass()
    field2.title = "Name"
    field2.value = name
    attachment.attach_field(field2)

    field2 = AttachmentFieldsClass()
    field2.title = "Email"
    field2.value = email
    attachment.attach_field(field2)

    field2 = AttachmentFieldsClass()
    field2.title = "Reason"
    field2.value = params['unsubscribe[reason]']
    attachment.attach_field(field2)

    # button_get_pipeline = MessageButtonsClass()
    # button_get_pipeline.name = "1"
    # button_get_pipeline.value = "1"
    # button_get_pipeline.text = "Get all pipelines"
    # button_get_pipeline.command = {
    #     "service_application": service_application,
    #     "function_name": 'list_pipelines',
    #     "data": {
    #         'data': "test",
    #     }
    # }

    # attachment.attach_button(button_get_pipeline)
    webhook_message.attach(attachment)
    # print(integration_id)
    webhook_message.data = {
        "Name": name,
        "Email": email,
        "Type": type,
        "Time": time,
    }

    # Creating yellowant object
    yellowant_user_integration_object = YellowAnt(access_token=access_token)

    # Sending webhook message to user
    send_message = yellowant_user_integration_object.create_webhook_message(
        requester_application=integration_id,
        webhook_name="contact-unsubscribe",
        **webhook_message.get_dict())
    return HttpResponse("OK", status=200)
Esempio n. 18
0
def campaign_share(request, webhook_id):
    """
            Webhook function to notify user about newly added pipeline
    """

    data = request.body.decode('utf-8')
    # print(type(data))
    urllib.parse.unquote(data)
    params_dict = urllib.parse.parse_qsl(data)
    params = dict(params_dict)

    email = params['contact[email]']
    name = params['contact[first_name]'] + " " + params['contact[last_name]']
    type = "Campaign Shared"
    shared_on = params['share[network]']
    time = params['date_time']
    # Fetching yellowant object
    yellow_obj = UserIntegration.objects.get(webhook_id=webhook_id)
    access_token = yellow_obj.yellowant_integration_token
    integration_id = yellow_obj.yellowant_integration_id
    service_application = str(integration_id)

    # Creating message object for webhook message
    webhook_message = MessageClass()
    attachment = MessageAttachmentsClass()
    webhook_message.message_text = "The Campaign is Shared by " + str(name)

    field2 = AttachmentFieldsClass()
    field2.title = "Email"
    field2.value = email
    attachment.attach_field(field2)

    field2 = AttachmentFieldsClass()
    field2.title = "Shared on"
    field2.value = params['share[network]']
    attachment.attach_field(field2)

    field2 = AttachmentFieldsClass()
    field2.title = "Share Content"
    field2.value = params['share[content]']
    attachment.attach_field(field2)

    # attachment.attach_button(button_get_pipeline)
    webhook_message.attach(attachment)
    # print(integration_id)
    webhook_message.data = {
        "Name": name,
        "Email": email,
        "Type": type,
        "Time": time,
        "Shared_on": shared_on,
    }

    # Creating yellowant object
    yellowant_user_integration_object = YellowAnt(access_token=access_token)

    # Sending webhook message to user
    send_message = yellowant_user_integration_object.create_webhook_message(
        requester_application=integration_id,
        webhook_name="campaign-share",
        **webhook_message.get_dict())
    print("aqsdfghj")
    return HttpResponse("OK", status=200)
Esempio n. 19
0
def webhook_unsubscribed(request, webhook_id):
    print("In webhook_unsubscribed")
    """
    Webhook function to notify user about update in unsbscribes
    """

    urllib.parse.unquote(request.body.decode("utf-8"))
    params_dict = urllib.parse.parse_qsl(request.body)
    params = dict(params_dict)

    ## Extracting necessary data

    device_type = params[b'device-type'].decode("utf-8")
    name = params[b'client-name'].decode("utf-8")
    domain = params[b'domain'].decode("utf-8")
    city = params[b'city'].decode('utf-8')
    country = params[b'country'].decode('utf-8')
    recipient = params[b'recipient'].decode('utf-8')

    try:

        # Fetching yellowant object
        yellow_obj = YellowUserToken.objects.get(webhook_id=webhook_id)
        print(yellow_obj)
        access_token = yellow_obj.yellowant_token
        print(access_token)
        integration_id = yellow_obj.yellowant_integration_id
        service_application = str(integration_id)
        print(service_application)

        # Creating message object for webhook message

        webhook_message = MessageClass()
        webhook_message.message_text = "Unsubscribe details"

        attachment_message = MessageAttachmentsClass()

        field2 = AttachmentFieldsClass()
        field2.title = "Email Id :"
        field2.value = recipient
        attachment_message.attach_field(field2)

        field1 = AttachmentFieldsClass()
        field1.title = "Browser :"
        field1.value = name
        attachment_message.attach_field(field1)

        field3 = AttachmentFieldsClass()
        field3.title = "Domain"
        field3.value = domain
        attachment_message.attach_field(field3)

        field4 = AttachmentFieldsClass()
        field4.title = "Device type"
        field4.value = device_type
        attachment_message.attach_field(field4)

        field5 = AttachmentFieldsClass()
        field5.title = "City"
        field5.value = city
        attachment_message.attach_field(field5)

        field6 = AttachmentFieldsClass()
        field6.title = "Country"
        field6.value = country
        attachment_message.attach_field(field6)

        webhook_message.attach(attachment_message)

        attachment = MessageAttachmentsClass()
        attachment.title = "Unsubscribe operations"

        button_get_incidents = MessageButtonsClass()
        button_get_incidents.name = "1"
        button_get_incidents.value = "1"
        button_get_incidents.text = "Get unsubscribe details"
        button_get_incidents.command = {
            "service_application": service_application,
            "function_name": 'get_unsubscribes',
            "data": {}
        }

        attachment.attach_button(button_get_incidents)
        webhook_message.data = {
            "recipient_email_id": recipient,
            "domain": domain,
            "device_type": device_type,
            "city": city,
            "country": country,
            "name": name,
        }
        webhook_message.attach(attachment)
        #print(integration_id)

        # Creating yellowant object
        yellowant_user_integration_object = YellowAnt(
            access_token=access_token)

        # Sending webhook message to user
        send_message = yellowant_user_integration_object.create_webhook_message(
            requester_application=integration_id,
            webhook_name="notify_unsubscribe",
            **webhook_message.get_dict())
        return HttpResponse("OK", status=200)

    except YellowUserToken.DoesNotExist:
        return HttpResponse("Not Authorized", status=403)
Esempio n. 20
0
def webhook(request, hash_str=""):
    print("Inside webhook")
    data = request.body
    if len(data) == 0:
        validationToken = request.GET['validationtoken']
        try:
            print("In try")
            return HttpResponse(validationToken, status=200)
        except:
            validationToken = None
            print("Error occured")
            return HttpResponse(status=400)
    else:
        try:
            message = MessageClass()
            attachment = MessageAttachmentsClass()
            response_json = json.loads(data)
            value_obj = response_json["value"]
            value = value_obj[0]
            SubscriptionId = value["SubscriptionId"]
            ResourceData = value["ResourceData"]
            message_id = ResourceData["Id"]
            ya_user = YellowUserToken.objects.get(
                subscription_id=SubscriptionId)
            """Make a request to get the message details using message_id"""
            get_message_details = graph_endpoint.format(
                "/me/messages/{}".format(message_id))
            webhook_request = make_api_call('GET', get_message_details,
                                            ya_user.outlook_access_token)
            response_json = webhook_request.json()
            subject = response_json["subject"]
            from_user = response_json["from"]
            email_address = from_user["emailAddress"]

            attachment.title = "Subject"
            attachment.text = str(subject)
            message.attach(attachment)

            forward_button = MessageButtonsClass()
            forward_button.text = "Forward"
            forward_button.value = "forward"
            forward_button.name = "forward"
            forward_button.command = {
                "service_application": ya_user.yellowant_integration_id,
                "function_name": "forward_message",
                "data": {
                    "Message-Id": str(message_id)
                },
                "inputs": ["toRecipients", "Message"]
            }
            attachment.attach_button(forward_button)

            reply_button = MessageButtonsClass()
            reply_button.text = "Reply"
            reply_button.value = "Reply"
            reply_button.name = "Reply"
            reply_button.command = {
                "service_application": ya_user.yellowant_integration_id,
                "function_name": "reply",
                "data": {
                    "Message-Id": str(message_id)
                },
                "inputs": ["Message"]
            }
            attachment.attach_button(reply_button)

            message.message_text = "Ola! You got a new E-mail from-" + email_address[
                "name"] + "( " + email_address["address"] + " )"
            yauser_integration_object = YellowAnt(
                access_token=ya_user.yellowant_token)
            print("Reached here")
            yauser_integration_object.create_webhook_message(
                requester_application=ya_user.yellowant_integration_id,
                webhook_name="inbox_webhook",
                **message.get_dict())
            return True

        except YellowUserToken.DoesNotExist:
            return HttpResponse("Not Authorized", status=403)
Esempio n. 21
0
def add_new_item(request, id):
    """
            Webhook function to notify user about newly added item
    """
    # print("in contacts")
    print(request.body)
    name = request.POST['name']
    item_id = request.POST['ID']
    price = request.POST['price']
    description = request.POST['description']

    # Fetching yellowant object
    yellow_obj = YellowUserToken.objects.get(webhook_id=id)
    access_token = yellow_obj.yellowant_token
    integration_id = yellow_obj.yellowant_integration_id
    # service_application = str(integration_id)

    # Creating message object for webhook message
    webhook_message = MessageClass()
    webhook_message.message_text = "New item added."

    attachment = MessageAttachmentsClass()

    field = AttachmentFieldsClass()
    field.title = "Item Name"
    field.value = name
    attachment.attach_field(field)

    field1 = AttachmentFieldsClass()
    field1.title = "Item ID"
    field1.value = item_id
    attachment.attach_field(field1)

    field2 = AttachmentFieldsClass()
    field2.title = "Price"
    field2.value = price
    attachment.attach_field(field2)

    field3 = AttachmentFieldsClass()
    field3.title = "Description"
    field3.value = description
    attachment.attach_field(field3)

    webhook_message.attach(attachment)
    # print(integration_id)
    webhook_message.data = {
        "Name": name,
        "ID": item_id,
        "Price": price,
        "Description": description,
    }

    # Creating yellowant object
    yellowant_user_integration_object = YellowAnt(access_token=access_token)

    # Sending webhook message to user
    yellowant_user_integration_object.create_webhook_message(
        requester_application=integration_id,
        webhook_name="new_item",
        **webhook_message.get_dict())
    return HttpResponse("OK", status=200)
Esempio n. 22
0
def webhook(request, hash_str=""):

    '''Respond to the webhook verification (GET request) by echoing back the challenge parameter.'''
    print("Inside webhook")

    if request.method == "GET":
        print("Inside webhook validation")
        challenge = request.GET.get('challenge',None)

        if challenge != None:
            return HttpResponse(challenge,status=200)
        else:
            return HttpResponse(status=400)

    else:
        print("In notifications")
        webhook_id = hash_str
        data =  (request.body.decode('utf-8'))
        response_json = json.loads(data)
        print(response_json)

        data = {
	            "users": [],
	            "accounts": []
            }

        try:
            yellow_obj = YellowUserToken.objects.get(webhook_id=webhook_id)
            print(yellow_obj)
            access_token = yellow_obj.yellowant_token
            print(access_token)
            integration_id = yellow_obj.yellowant_integration_id
            service_application = str(integration_id)
            print(service_application)

            # Creating message object for webhook message

            webhook_message = MessageClass()
            webhook_message.message_text = "File/Folder updated !"
            attachment = MessageAttachmentsClass()
            attachment.title = "Updated file/folder details :"

            for i in range(0,len(response_json['list_folder']['accounts'])):
                field1 = AttachmentFieldsClass()
                field1.title = "Id : "
                field1.value = response_json['list_folder']['accounts'][i]
                data["accounts"].append(response_json['list_folder']['accounts'][i])
                attachment.attach_field(field1)

            attachment2 = MessageAttachmentsClass()
            attachment2.title = "User update details :"

            for i in range(0, len(response_json['delta']['users'])):
                field2 = AttachmentFieldsClass()
                field2.title = "Id : "
                field2.value = response_json['delta']['users'][i]
                data["users"].append(response_json['delta']['users'][i])
                attachment2.attach_field(field2)

            button = MessageButtonsClass()
            button.name = "1"
            button.value = "1"
            button.text = "Get all files and folders "
            button.command = {
                "service_application": service_application,
                "function_name": 'get_all_folders',
                "data" : {"path": "",
                "recursive": True,
                "include_media_info": False,
                "include_deleted": False,
                "include_has_explicit_shared_members": False,
                "include_mounted_folders": True}
                }

            attachment.attach_button(button)
            webhook_message.attach(attachment)
            webhook_message.attach(attachment2)
            #print(integration_id)
            print("-----------")
            print(data)
            print("------------")
            webhook_message.data = data
            # Creating yellowant object
            yellowant_user_integration_object = YellowAnt(access_token=access_token)

            # Sending webhook message to user
            send_message = yellowant_user_integration_object.create_webhook_message(
                requester_application=integration_id,
                webhook_name="files_folders_update", **webhook_message.get_dict())

            return HttpResponse("OK", status=200)

        except YellowUserToken.DoesNotExist:
            return HttpResponse("Not Authorized", status=403)
Esempio n. 23
0
def add_new_user(request, webhook_id):
    """
        Webhook function to notify user about newly added user
    """

    # Extracting necessary data
    data = request.body
    data_string = data.decode('utf-8')
    data_json = json.loads(data_string)

    ID = data_json["current"][0]['id']
    name = data_json["current"][0]['name']
    Default_currency = data_json["current"][0]['default_currency']
    Email = data_json["current"][0]['email']
    phone = "-" if data_json["current"][0]['phone'] is None else data_json[
        "current"][0]['phone']

    # Fetching yellowant object
    yellow_obj = YellowUserToken.objects.get(webhook_id=webhook_id)
    access_token = yellow_obj.yellowant_token
    integration_id = yellow_obj.yellowant_integration_id
    service_application = str(integration_id)

    # Creating message object for webhook message
    webhook_message = MessageClass()
    webhook_message.message_text = "New user added."+"\n" + "The username : "******"\nThe Email ID:" + str(Email)
    attachment = MessageAttachmentsClass()
    attachment.title = "Get user details"

    button_get_users = MessageButtonsClass()
    button_get_users.name = "1"
    button_get_users.value = "1"
    button_get_users.text = "Get all users"
    button_get_users.command = {
        "service_application": service_application,
        "function_name": 'list_users',
        "data": {
            'data': "test",
        }
    }

    attachment.attach_button(button_get_users)
    webhook_message.attach(attachment)
    # print(integration_id)
    # userinfo = response['data']
    # phone = "-" if userinfo['phone'] is None else userinfo['phone']
    webhook_message.data = {
        "name": name,
        "ID": ID,
        "Email": Email,
        "Phone": phone,
        "Default currency": Default_currency
    }

    # Creating yellowant object
    yellowant_user_integration_object = YellowAnt(access_token=access_token)

    # Sending webhook message to user
    send_message = yellowant_user_integration_object.create_webhook_message(
        requester_application=integration_id,
        webhook_name="new_user",
        **webhook_message.get_dict())

    return HttpResponse("OK", status=200)
Esempio n. 24
0
def startGameAgainstPlayer(args,user_integration):
    """

    """


    player_object = UserIntegration.objects.get(yellowant_integration_id=user_integration.yellowant_integration_id)

    opponent_object = UserIntegration.objects.get(yellowant_integration_id=player_object.opponent_integration_id)

    board = chess.Board(player_object.board_state)
    color = args['Color']

    attachment = MessageAttachmentsClass()

    print(color + " to move")

    if (color=="Black"):
        webhook_message = MessageClass()
        webhook_message.message_text = "You are playing White!"
        attachment = MessageAttachmentsClass()
        button = MessageButtonsClass()
        button.text = "Make Move"
        button.value = "Make Move"
        button.name = "Make Move"
        button.command = {
            "service_application": str(opponent_object.yellowant_integration_id),
            "function_name": "makemoveagainst",
            "data": {"user_int": player_object.yellowant_integration_id},
        }
        attachment.attach_button(button)

        webhook_message.attach(attachment)
        access_token = opponent_object.yellowant_integration_token
        yellowant_user_integration_object = YellowAnt(access_token=access_token)

        send_message = yellowant_user_integration_object.create_webhook_message(
            requester_application=opponent_object.yellowant_integration_id,
            webhook_name="webhook", **webhook_message.get_dict())

        return

    else:
        print("Inside else")
        m = MessageClass()
        attachment = MessageAttachmentsClass()
        attachment.image_url = IMAGE_URL + INITIAL_BOARD
        m.message_text = "Make a Move"
        field1 = AttachmentFieldsClass()
        field1.title = "Move"
        field1.value = color + " to move"
        attachment.attach_field(field1)

        attachment.image_url = IMAGE_URL + INITIAL_BOARD


        button = MessageButtonsClass()
        button.text = "Make Move"
        button.value = "Make Move"
        button.name = "Make Move"
        button.command = {
            "service_application": str(player_object.yellowant_integration_id),
            "function_name": "makemoveagainst",
            "inputs": ["move"],
            "data": {"user_int": player_object.yellowant_integration_id},
        }
        attachment.attach_button(button)

        m.attach(attachment)

        return m
Esempio n. 25
0
def add_new_activity(request, webhook_id):
    """
                Webhook function to notify user about newly added pipeline
        """

    data = request.body
    data_string = data.decode('utf-8')
    data_json = json.loads(data_string)

    title = data_json["current"]['deal_title']
    handled_by = data_json["current"]['owner_name']
    name = data_json["current"]['person_name']
    company = data_json["current"]['org_name']
    deal_email = data_json["current"]['deal_dropbox_bcc']
    activity_type = data_json["current"]['type']
    due_date = data_json["current"]['due_date']

    # Fetching yellowant object
    yellow_obj = YellowUserToken.objects.get(webhook_id=webhook_id)
    access_token = yellow_obj.yellowant_token
    integration_id = yellow_obj.yellowant_integration_id
    service_application = str(integration_id)

    # Creating message object for webhook message
    webhook_message = MessageClass()
    webhook_message.message_text = "New activity added."+"\n" + "The deal name : " + str(title) + "\nThe activity date:" \
                                   + str(due_date)
    attachment = MessageAttachmentsClass()

    button_get_activity = MessageButtonsClass()
    button_get_activity.name = "1"
    button_get_activity.value = "1"
    button_get_activity.text = "Get all activities"
    button_get_activity.command = {
        "service_application": service_application,
        "function_name": 'list_activities',
        "data": {
            'data': "test",
        }
    }

    attachment.attach_button(button_get_activity)
    webhook_message.attach(attachment)
    # print(integration_id)
    webhook_message.data = {
        "Handled by": handled_by,
        "Contact Person": name,
        "Due Date": due_date,
        "Deal Title": title,
        "Activity Type": activity_type,
        "Company": company,
        "Deal_email": deal_email
    }

    # Creating yellowant object
    yellowant_user_integration_object = YellowAnt(access_token=access_token)

    # Sending webhook message to user
    send_message = yellowant_user_integration_object.create_webhook_message(
        requester_application=integration_id,
        webhook_name="new_activity",
        **webhook_message.get_dict())
    return HttpResponse("OK", status=200)
Esempio n. 26
0
def add_new_deal(request, webhook_id):
    """
        Webhook function to notify user about newly added deal
    """

    # Extracting necessary data
    data = request.body
    data_string = data.decode('utf-8')
    data_json = json.loads(data_string)

    title = data_json["current"]['title']
    handled_by = data_json["current"]['owner_name']
    name = data_json["current"]['person_name']
    currency = data_json["current"]['currency']
    company = data_json["current"]['org_name']
    value = data_json["current"]['value']
    deal_email = data_json["current"]['cc_email']

    # Fetching yellowant object
    yellow_obj = YellowUserToken.objects.get(webhook_id=webhook_id)
    access_token = yellow_obj.yellowant_token
    integration_id = yellow_obj.yellowant_integration_id
    service_application = str(integration_id)

    # Creating message object for webhook message
    webhook_message = MessageClass()
    webhook_message.message_text = "New deal created."+"\n" + "The deal name : " + str(title) + "\nThe deal value:" \
                                   + str(currency)+" "+str(value)
    attachment = MessageAttachmentsClass()

    button_get_deal = MessageButtonsClass()
    button_get_deal.name = "1"
    button_get_deal.value = "1"
    button_get_deal.text = "Get all deals"
    button_get_deal.command = {
        "service_application": service_application,
        "function_name": 'list_all_deals',
        "data": {
            'data': "test",
        }
    }

    attachment.attach_button(button_get_deal)
    webhook_message.attach(attachment)
    # print(integration_id)
    webhook_message.data = {
        "Handled by": handled_by,
        "Name": name,
        "Title": title,
        "Company": company,
        "Value": value,
        "Currency": currency,
        "Deal_email": deal_email
    }

    # Creating yellowant object
    yellowant_user_integration_object = YellowAnt(access_token=access_token)

    # Sending webhook message to user
    send_message = yellowant_user_integration_object.create_webhook_message(
        requester_application=integration_id,
        webhook_name="new_deal",
        **webhook_message.get_dict())
    return HttpResponse("OK", status=200)
Esempio n. 27
0
def add_new_customer(request, webhook_id):
    """
    Webhook function to notify user about newly created customer
    """
    print("In add_new_customer")
    print(webhook_id)
    # Extracting necessary data

    code = request.GET.get("code", False)

    if code == request.codes.ok:
        data = (request.body.decode('utf-8'))
        response_json = json.loads(data)
        print(response_json)

        try:
            yellow_obj = YellowUserToken.objects.get(webhook_id=webhook_id)
            print(yellow_obj)
            access_token = yellow_obj.yellowant_token
            print(access_token)
            integration_id = yellow_obj.yellowant_integration_id
            #QuickbookUserToken.objects.get(realmId=response_json['eventNotifications'][0]['realmId']).user_integration_id
            service_application = str(integration_id)
            print(service_application)

            # Creating message object for webhook message
            webhook_message = MessageClass()
            id = str(response_json['eventNotifications'][0]['dataChangeEvent']
                     ['entities'][0]['id'])
            webhook_message.message_text = "New customer added\n" + "ID :" + str(
                response_json['eventNotifications'][0]['dataChangeEvent']
                ['entities'][0]['id'])
            attachment = MessageAttachmentsClass()
            attachment.title = "Get all customer details"

            button_get_incidents = MessageButtonsClass()
            button_get_incidents.name = "1"
            button_get_incidents.value = "1"
            button_get_incidents.text = "Get customer details"
            button_get_incidents.command = {
                "service_application": service_application,
                "function_name": 'get_customer_details',
                "data": {
                    "customer_id": id
                }
            }

            attachment.attach_button(button_get_incidents)

            webhook_message.data = {"customer_id": id}
            webhook_message.attach(attachment)
            #print(integration_id)

            # Creating yellowant object
            yellowant_user_integration_object = YellowAnt(
                access_token=access_token)

            # Sending webhook message to user
            send_message = yellowant_user_integration_object.create_webhook_message(
                requester_application=integration_id,
                webhook_name="new_customer",
                **webhook_message.get_dict())
            return HttpResponse("OK", status=200)

        except YellowUserToken.DoesNotExist:
            return HttpResponse("Not Authorized", status=403)
    else:
        return HttpResponse(status=400)
Esempio n. 28
0
def makeMoveAgainst(args,user_integration):
    player_object = UserIntegration.objects.get(yellowant_integration_id=user_integration.yellowant_integration_id)
    opponent_object = UserIntegration.objects.get(yellowant_integration_id=player_object.opponent_integration_id)

    access_token = opponent_object.yellowant_integration_token
    yellowant_user_integration_object = YellowAnt(access_token=access_token)

    move = args.get("move")
    board = chess.Board(player_object.board_state)
    col = color_inv(player_object.board_state[-12])

    m = MessageClass()

    m.message_text = col + " to move"
    move_uci = board.parse_san(move)
    if move_uci in board.legal_moves:
        board.push_san(move)
        if board.is_insufficient_material():
            print("Insufficient material")
            m.message_text = "Insufficient material"
            endGame(args, user_integration)

            webhook_message = MessageClass()
            webhook_field = AttachmentFieldsClass()
            webhook_field.title = "Result"
            webhook_field.value = "Game drawn due to insufficient material"
            attachmentImage = MessageAttachmentsClass()
            attachmentImage.image_url = IMAGE_URL + board.fen()[:-13]
            attachmentImage.attach_field(webhook_field)
            webhook_message.attach(attachmentImage)





        if board.is_stalemate():
            print("Stalemate")
            m.message_text = "Stalemate"
            endGame(args, user_integration)
        if board.is_checkmate():
            print(col + " wins")
            m.message_text = col + " wins"
            endGame(args, user_integration)

        player_object.board_state = board.fen()
        opponent_object.board_state = board.fen()

        player_object.save()
        opponent_object.save()



    else:
        m.message_text = "Invalid move"
        return m

    attachment = MessageAttachmentsClass()
    attachment.image_url = IMAGE_URL + board.fen()[:-13]

    m.attach(attachment)
    webhook_message = MessageClass()
    webhook_field = AttachmentFieldsClass()
    webhook_field.title = "Move"
    webhook_field.value = col + " to move"
    attachmentImage = MessageAttachmentsClass()
    attachmentImage.attach_field(webhook_field)
    attachmentImage.image_url = IMAGE_URL + board.fen()[:-13]

    button = MessageButtonsClass()
    button.text = "Make Move"
    button.value = "Make Move"
    button.name = "Make Move"
    button.command = {
        "service_application": str(opponent_object.yellowant_integration_id),
        "function_name": "makemoveagainst",
        "inputs": ["move"],
        "data": {"user_int": player_object.yellowant_integration_id},
    }
    attachmentImage.attach_button(button)

    webhook_message.attach(attachmentImage)



    send_message = yellowant_user_integration_object.create_webhook_message(
        requester_application=opponent_object.yellowant_integration_id,
        webhook_name="webhook", **webhook_message.get_dict())

    return m