예제 #1
0
    def get_my_messages(self, args):
        """Returns the messages of the inbox folder"""
        print("In get_my_messages")
        get_messages_url = graph_endpoint.format(
            '/me/mailfolders/inbox/messages')

        # Use OData query parameters to control the results
        #  - Only first 10 results returned
        #  - Only return the ReceivedDateTime, Subject, and From fields
        #  - Sort the results by the ReceivedDateTime field in descending order
        query_parameters = {
            '$top': '10',
            '$select': 'receivedDateTime,subject,from',
            '$orderby': 'receivedDateTime DESC'
        }

        r = make_api_call('GET',
                          get_messages_url,
                          self.access_token,
                          parameters=query_parameters)
        if r.status_code == requests.codes.ok:

            r_json = r.json()
            obj1 = r_json["value"]
            print(r_json)
            message = MessageClass()
            for i in range(0, len(obj1)):
                obj = obj1[i]
                id = obj["id"]
                bodyPreview = self.list_messages(args, id=id)

                attachment = MessageAttachmentsClass()
                attachment.title = "Subject"
                attachment.text = str(obj["subject"])

                field1 = AttachmentFieldsClass()
                field1.title = "Received Date Time"
                field1.value = str(obj["receivedDateTime"])
                attachment.attach_field(field1)

                if bodyPreview != None:
                    field2 = AttachmentFieldsClass()
                    field2.title = "Body Preview"
                    field2.value = str(bodyPreview)
                    attachment.attach_field(field2)

                from_obj = obj["from"]
                for j in range(0, len(from_obj)):
                    emailAddress = from_obj["emailAddress"]
                    field3 = AttachmentFieldsClass()
                    field3.title = "From"
                    field3.value = emailAddress["name"]
                    attachment.attach_field(field3)

                    field4 = AttachmentFieldsClass()
                    field4.title = "Email Id"
                    field4.value = emailAddress["address"]
                    attachment.attach_field(field4)

                button1 = MessageButtonsClass()
                button1.text = "Forward"
                button1.value = "forward"
                button1.name = "forward"
                button1.command = {
                    "service_application":
                    self.user_integration.yellowant_integration_id,
                    "function_name": "forward_message",
                    "data": {
                        "Message-Id": str(obj["id"])
                    },
                    "inputs": ["toRecipients", "Message"]
                }

                attachment.attach_button(button1)

                button2 = MessageButtonsClass()
                button2.text = "Reply"
                button2.value = "Reply"
                button2.name = "Reply"
                button2.command = {
                    "service_application":
                    self.user_integration.yellowant_integration_id,
                    "function_name": "reply",
                    "data": {
                        "Message-Id": str(obj["id"])
                    },
                    "inputs": ["Message"]
                }

                attachment.attach_button(button2)

                message.attach(attachment)
            message.message_text = "Inbox messages are"

            return message.to_json()
        else:
            print(r.text)
            return "{0}: {1}".format(r.status_code, r.text)
예제 #2
0
    def get_message_byfolder(self, args):
        """This function returns the messages of a particular folder.
        The name of the folder is provided as input by the user.
        If the folder is Empty it returns 'Empty Folder' """
        print("In get_message_byfolder")
        folder_name = args["Folder-Name"]
        folder_name = folder_name.strip()
        folder_name = folder_name.replace(" ", "")
        get_foldermessages_url = graph_endpoint.format(
            '/me/mailfolders/{}/messages'.format(folder_name))

        query_parameters = {
            '$top': '10',
            '$select': 'receivedDateTime,subject,from',
            '$orderby': 'receivedDateTime DESC'
        }

        r = make_api_call('GET',
                          get_foldermessages_url,
                          self.access_token,
                          parameters=query_parameters)
        print(r.json())
        value = r.json()["value"]
        message = MessageClass()

        if len(value) == 0:
            message.message_text = "Empty Folder"
            return message.to_json()

        if r.status_code == requests.codes.ok:
            for i in range(0, len(value)):
                obj = value[i]

                id = obj["id"]
                bodyPreview = self.list_messages(args, id=id)

                attachment = MessageAttachmentsClass()
                attachment.title = "Subject"
                attachment.text = str(obj["subject"])

                field1 = AttachmentFieldsClass()
                field1.title = "Received Date Time"
                field1.value = str(obj["receivedDateTime"])
                attachment.attach_field(field1)

                if bodyPreview != None:
                    field2 = AttachmentFieldsClass()
                    field2.title = "Body Preview"
                    field2.value = str(bodyPreview)
                    attachment.attach_field(field2)

                from_obj = obj["from"]
                for j in range(0, len(from_obj)):
                    emailAddress = from_obj["emailAddress"]
                    field3 = AttachmentFieldsClass()
                    field3.title = "From"
                    field3.value = emailAddress["name"]
                    attachment.attach_field(field3)

                    field4 = AttachmentFieldsClass()
                    field4.title = "Email Id"
                    field4.value = emailAddress["address"]
                    attachment.attach_field(field4)

                message.attach(attachment)
                message.message_text = "messages are"
                print("returning mailfolder")
                if i == (len(value) - 1):
                    return message.to_json()
                else:
                    continue
        else:
            print(r.text)
            return "{0}: {1}".format(r.status_code, r.text)
예제 #3
0
    def View_Survey_Details(self, args):
        # Gives the details of the survey(whichever the user chooses).
        print("In view_details")
        survey_id = args["SurveyId"]

        url = ("https://api.surveymonkey.com/v3/surveys/%s") % (survey_id)
        response = requests.get(url, headers=self.headers)
        response_json = response.json()
        print(response_json)
        title = response_json["title"]
        message = MessageClass()
        attachment = MessageAttachmentsClass()
        message.message_text = title

        field1 = AttachmentFieldsClass()
        field1.title = "Response Count"
        field1.value = response_json["response_count"]
        attachment.attach_field(field1)

        field2 = AttachmentFieldsClass()
        field2.title = "Date Created"
        field2.value = response_json["date_created"]
        attachment.attach_field(field2)

        field3 = AttachmentFieldsClass()
        field3.title = "Question Count"
        field3.value = response_json["question_count"]
        attachment.attach_field(field3)

        field4 = AttachmentFieldsClass()
        field4.title = "Category"
        field4.value = response_json["category"]
        attachment.attach_field(field4)

        field5 = AttachmentFieldsClass()
        field5.title = "Category"
        field5.value = response_json["category"]
        attachment.attach_field(field5)

        field7 = AttachmentFieldsClass()
        field7.title = "Ownership"
        field7.value = response_json["is_owner"]
        attachment.attach_field(field7)

        field8 = AttachmentFieldsClass()
        field8.title = "Date modified"
        field8.value = response_json["date_modified"]
        attachment.attach_field(field8)

        field6 = AttachmentFieldsClass()
        field6.title = "Survey Preview"
        field6.value = "<{}|Preview>".format(response_json["preview"])
        attachment.attach_field(field6)

        field9 = AttachmentFieldsClass()
        field9.title = "Analyze Survey"
        field9.value = "<{}|Analyze>".format(response_json["analyze_url"])
        attachment.attach_field(field9)

        field10 = AttachmentFieldsClass()
        field10.title = "Survey summary"
        field10.value = "<{}|Summary>".format(response_json["summary_url"])
        attachment.attach_field(field10)

        field11 = AttachmentFieldsClass()
        field11.title = "Edit survey"
        field11.value = "<{}|Edit>".format(response_json["edit_url"])
        attachment.attach_field(field11)

        field12 = AttachmentFieldsClass()
        field12.title = "View Response"
        field12.value = "<{}|Edit>".format(response_json["collect_url"])
        attachment.attach_field(field12)

        message.attach(attachment)

        # use inbuilt sdk method to_json to return message in a json format accepted by YA
        return message.to_json()