def test_find_all_read(self):
     # Iterate over through all conversations (read + unread) with a
     # user based on the users email
     for convo in Conversation.find_all(email=self.email,
                                        type='user',
                                        unread=False):
         self.assertIsNotNone(convo.id)
    def setup_class(cls):
        # get admin
        cls.admin = Admin.all()[1]

        # get user
        timestamp = get_timestamp()
        cls.user = get_or_create_user(timestamp)
        cls.email = cls.user.email

        # send user message
        message_data = {
            'from': {
                'type': "user",
                'id': cls.user.id
            },
            'body': "Hey"
        }
        cls.user_message = Message.create(**message_data)

        conversations = Conversation.find_all()
        user_init_conv = conversations[0]
        # send admin reply
        cls.admin_conv = user_init_conv.reply(type='admin',
                                              admin_id=cls.admin.id,
                                              message_type='comment',
                                              body='There')
    def setup_class(cls):
        # get admin
        cls.admin = Admin.all()[1]

        # get user
        timestamp = get_timestamp()
        cls.user = get_or_create_user(timestamp)
        cls.email = cls.user.email

        # send user message
        message_data = {
            'from': {
                'type': "user",
                'id': cls.user.id
            },
            'body': "Hey"
        }
        cls.user_message = Message.create(**message_data)

        conversations = Conversation.find_all()
        user_init_conv = conversations[0]
        # send admin reply
        cls.admin_conv = user_init_conv.reply(
            type='admin', admin_id=cls.admin.id,
            message_type='comment', body='There')
 def test_find_all_unread(self):
     # Iterate over all unread conversations with a user based on the
     # users email
     for convo in Conversation.find_all(email=self.email,
                                        type='user',
                                        unread=True):
         self.assertIsNotNone(convo.id)
示例#5
0
def fetch_new_conversation(context):
    cursor = table.get_item(Key={
        'project': 'intercom',
        'id': 'conversation'
    },
                            AttributesToGet=['value'])
    if "Item" in cursor:
        max_id = cursor.get('Item').get('value')
    else:
        max_id = 0

    events = []
    for convo in Conversation.find_all(after=max_id):
        event = {
            'assignee_type': None,
            'assignee_id': convo.assignee.id,
            'subject': convo.conversation_message.subject,
            'author_id': convo.conversation_message.author.id,
            'author_type': None,
            '_time': convo.created_at.isoformat("T"),
            '_user': convo.user.user_id or convo.user.email or convo.user.id
        }
        max_id = max(int(convo.id), max_id)
        events.append({
            'collection': context.get('collection_prefix') + '_conversation',
            'properties': event
        })

    response = requests.post(context.get('rakam_api_url') + "/event/batch",
                             data=json.dumps({
                                 'events': events,
                                 'api': {
                                     'api_key': context.get('rakam_write_key')
                                 }
                             }),
                             headers={'Content-type': 'application/json'})

    if len(events) == 0:
        return

    if response.status_code != 200:
        print('[event] Invalid status code from Rakam {} with response {}'.
              format(response.status_code, response.text))
    else:
        print(
            "[event] collected {} events between {} and {}, new cursor is {}".
            format(len(events), events[0].get('properties').get('_time'),
                   events[len(events) - 1].get('properties').get('_time'),
                   max_id))

    table.update_item(Key={
        'project': 'intercom',
        'id': 'conversation'
    },
                      UpdateExpression='SET #keyval = :val1',
                      ExpressionAttributeNames={'#keyval': 'value'},
                      ExpressionAttributeValues={':val1': max_id})
    def test_conversation_parts(self):
        # INTERACTING WITH THE PARTS OF A CONVERSATION
        convo_id = Conversation.find_all(type='admin', id=self.admin.id)[0].id
        conversation = Conversation.find(id=convo_id)

        # Getting the subject of a part (only applies to email-based
        # conversations)
        self.assertEqual(conversation.conversation_message.subject, "")
        for part in conversation.conversation_parts:
            # There is a part_type
            self.assertIsNotNone(part.part_type)
            # There is a body
            self.assertIsNotNone(part.body)
    def test_conversation_parts(self):
        # INTERACTING WITH THE PARTS OF A CONVERSATION
        convo_id = Conversation.find_all(type='admin', id=self.admin.id)[0].id
        conversation = Conversation.find(id=convo_id)

        # Getting the subject of a part (only applies to email-based
        # conversations)
        self.assertEqual(conversation.conversation_message.subject, "")
        for part in conversation.conversation_parts:
            # There is a part_type
            self.assertIsNotNone(part.part_type)
            # There is a body
            self.assertIsNotNone(part.body)
 def test_find_single_conversation(self):
     # FINDING A SINGLE CONVERSATION
     convo_id = Conversation.find_all(type='admin', id=self.admin.id)[0].id
     conversation = Conversation.find(id=convo_id)
     self.assertEqual(conversation.id, convo_id)
 def test_find_single_conversation(self):
     # FINDING A SINGLE CONVERSATION
     convo_id = Conversation.find_all(type='admin', id=self.admin.id)[0].id
     conversation = Conversation.find(id=convo_id)
     self.assertEqual(conversation.id, convo_id)
示例#10
0
def intercom_conversations():
    conversations = Conversation.find_all(open=True)
    print(conversations)
示例#11
0
 def test_find_all_closed_before_admin(self):
     for convo in Conversation.find_all(type='admin',
                                        id=self.admin.id,
                                        open=False,
                                        before=1374844930):
         self.assertIsNotNone(convo.id)
 def test_find_all_closed_before_admin(self):
     for convo in Conversation.find_all(
             type='admin', id=self.admin.id, open=False,
             before=1374844930):
         self.assertIsNotNone(convo.id)
 def test_find_all_closed_admin(self):
     # Iterate over closed conversations assigned to an admin
     for convo in Conversation.find_all(
             type='admin', id=self.admin.id, open=False):
         self.assertIsNotNone(convo.id)
 def test_find_all_admin(self):
     # FINDING CONVERSATIONS FOR AN ADMIN
     # Iterate over all conversations (open and closed) assigned to an admin
     for convo in Conversation.find_all(type='admin', id=self.admin.id):
         self.assertIsNotNone(convo.id)
         self.admin_conv.id = convo.id
示例#15
0
 def test_find_all_admin(self):
     # FINDING CONVERSATIONS FOR AN ADMIN
     # Iterate over all conversations (open and closed) assigned to an admin
     for convo in Conversation.find_all(type='admin', id=self.admin.id):
         self.assertIsNotNone(convo.id)
         self.admin_conv.id = convo.id
示例#16
0
 def test_find_all_closed_admin(self):
     # Iterate over closed conversations assigned to an admin
     for convo in Conversation.find_all(type='admin',
                                        id=self.admin.id,
                                        open=False):
         self.assertIsNotNone(convo.id)
 def test_find_all_user(self):
     # FINDING CONVERSATIONS FOR A USER
     # Iterate over all conversations (read + unread, correct) with a
     # user based on the users email
     for convo in Conversation.find_all(email=self.email, type='user'):
         self.assertIsNotNone(convo.id)
示例#18
0
 def test_find_all_user(self):
     # FINDING CONVERSATIONS FOR A USER
     # Iterate over all conversations (read + unread, correct) with a
     # user based on the users email
     for convo in Conversation.find_all(email=self.email, type='user'):
         self.assertIsNotNone(convo.id)
 def test_find_all_read(self):
     # Iterate over through all conversations (read + unread) with a
     # user based on the users email
     for convo in Conversation.find_all(
             email=self.email, type='user', unread=False):
         self.assertIsNotNone(convo.id)
 def test_find_all_unread(self):
     # Iterate over all unread conversations with a user based on the
     # users email
     for convo in Conversation.find_all(
             email=self.email, type='user', unread=True):
         self.assertIsNotNone(convo.id)
示例#21
0
def stuff_with_all_convos():
    for admin in Admin.all():
        # need to add unassigned since there will be a lot of those
        for convo in Conversation.find_all(type='admin', id=admin.id):
            print convo.id