Exemplo n.º 1
0
 def test_link_message(self):
     message = LinkMessage(url='http://foo.bar', to='aleem').to_json()
     self.assertEqual(message, {
         'type': 'link',
         'to': 'aleem',
         'url': 'http://foo.bar'
     })
Exemplo n.º 2
0
def abstract_kik_message(to,chat_id,content,msg_type):
    if msg_type == 'text':
        return TextMessage(to=to,chat_id=chat_id,body=content)
    if msg_type == 'image':
        return PictureMessage(to=to,chat_id=chat_id,pic_url=content)
    if msg_type == 'link':
        return LinkMessage(to=to,chat_id=chat_id,url=content)
Exemplo n.º 3
0
    def test_link_message_incoming(self):
        message = LinkMessage.from_json({
            'from': 'aleem',
            'participants': ['aleem'],
            'mention': None,
            'chatId': 'c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2',
            'url': 'http://foo.bar',
            'title': 'A Title',
            'text': 'Some text',
            'noForward': True,
            'kikJsData': 'somedata',
            'attribution': {
                'name': 'Webpage',
                'iconUrl': 'http://foo.bar/icon'
            },
            'id': '8e7fc0ad-36aa-43dd-8c5f-e72f5f2ed7e0',
            'timestamp': 1458336131,
            'readReceiptRequested': True
        })

        self.assertEqual(message.from_user, 'aleem')
        self.assertEqual(message.participants, ['aleem'])
        self.assertIsNone(message.mention)
        self.assertEqual(message.chat_id, 'c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2')
        self.assertEqual(message.url, 'http://foo.bar')
        self.assertEqual(message.title, 'A Title')
        self.assertEqual(message.text, 'Some text')
        self.assertEqual(message.no_forward, True)
        self.assertEqual(message.kik_js_data, 'somedata')
        self.assertEqual(message.attribution.name, 'Webpage')
        self.assertEqual(message.attribution.icon_url, 'http://foo.bar/icon')
        self.assertEqual(message.id, '8e7fc0ad-36aa-43dd-8c5f-e72f5f2ed7e0')
        self.assertEqual(message.timestamp, 1458336131)
        self.assertIs(True, message.read_receipt_requested)
Exemplo n.º 4
0
    def test_link_message_incoming(self):
        message = LinkMessage.from_json({
            'from': 'aleem',
            'participants': ['aleem'],
            'mention': None,
            'chatId': 'c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2',
            'url': 'http://foo.bar',
            'title': 'A Title',
            'text': 'Some text',
            'noForward': True,
            'kikJsData': 'somedata',
            'attribution': {
                'name': 'Webpage',
                'iconUrl': 'http://foo.bar/icon'
            },
            'id': '8e7fc0ad-36aa-43dd-8c5f-e72f5f2ed7e0',
            'timestamp': 1458336131,
            'readReceiptRequested': True
        })

        self.assertEqual(message.from_user, 'aleem')
        self.assertEqual(message.participants, ['aleem'])
        self.assertIs(None, message.mention)
        self.assertEqual(message.chat_id, 'c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2')
        self.assertEqual(message.url, 'http://foo.bar')
        self.assertEqual(message.title, 'A Title')
        self.assertEqual(message.text, 'Some text')
        self.assertEqual(message.no_forward, True)
        self.assertEqual(message.kik_js_data, 'somedata')
        self.assertEqual(message.attribution.name, 'Webpage')
        self.assertEqual(message.attribution.icon_url, 'http://foo.bar/icon')
        self.assertEqual(message.id, '8e7fc0ad-36aa-43dd-8c5f-e72f5f2ed7e0')
        self.assertEqual(message.timestamp, 1458336131)
        self.assertIs(True, message.read_receipt_requested)
Exemplo n.º 5
0
    def test_link_message_complete(self):
        message = LinkMessage(
            url='http://foo.bar',
            to='aleem',
            mention='anotherbot',
            chat_id=
            'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855',
            title='A Title',
            text='Some Text',
            pic_url='http://foo.bar/image',
            no_forward=True,
            kik_js_data='foobar',
            keyboards=[
                SuggestedResponseKeyboard(hidden=True,
                                          responses=[TextResponse('Foo')])
            ],
            attribution=CustomAttribution(name='Foobar'),
            delay=100).to_json()

        self.assertEqual(
            message, {
                'type':
                'link',
                'to':
                'aleem',
                'url':
                'http://foo.bar',
                'mention':
                'anotherbot',
                'chatId':
                'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855',
                'title':
                'A Title',
                'text':
                'Some Text',
                'picUrl':
                'http://foo.bar/image',
                'noForward':
                True,
                'kikJsData':
                'foobar',
                'keyboards': [{
                    'type': 'suggested',
                    'hidden': True,
                    'responses': [{
                        'type': 'text',
                        'body': 'Foo'
                    }]
                }],
                'attribution': {
                    'name': 'Foobar'
                },
                'delay':
                100
            })
Exemplo n.º 6
0
def send_link(user, chat_id, url=None, title=None, text=None, pic_url=None):
    """Send link."""
    kik.send_messages([
        LinkMessage(
            to=user,
            chat_id=chat_id,
            url=url,
            title=title,
            pic_url=pic_url,
        )
    ])
Exemplo n.º 7
0
def seeResultsOnWebsite(chat_id, context):
    from_user = context['from_user']
    img_url = context['user_img_url']
    msg = LinkMessage(to=from_user,
                      chat_id=chat_id,
                      url='http://gofindfashion.com?' + img_url,
                      title="Go Find Fashion Seach Engine")
    msg.keyboards.append(
        SuggestedResponseKeyboard(responses=[
            TextResponse('See more results'),
            TextResponse('Search with this pic'),
            TextResponse('New search')
        ]))
    kik.send_messages([msg])
Exemplo n.º 8
0
def send_messages(message,
                  inc_url="",
                  text_to_send="",
                  instant_pic="",
                  link=0,
                  inc_title=""):
    """Send the search results to the client."""

    if link:
        kik.send_messages([
            LinkMessage(to=message.from_user,
                        chat_id=message.chat_id,
                        url=inc_url,
                        pic_url=instant_pic,
                        text=text_to_send,
                        title=inc_title)
        ])
    else:
        kik.send_messages([
            TextMessage(to=message.from_user,
                        chat_id=message.chat_id,
                        body=text_to_send)
        ])
Exemplo n.º 9
0
def buyThis(chat_id, context):
    """
    User has selected a picture she likes, and would like to visit the
    store webpage
    """
    from_user = context['from_user']
    prev_context = retrieveContext(chat_id, from_user)
    if 'image_query_result' not in prev_context and 'text_query_result' not in prev_context:
        say(chat_id, context,
            canned_responses.error_message() + 'query results issue')
    elif 'selected_outfit' not in prev_context:
        say(chat_id, context,
            canned_responses.error_message() + 'selection issuse')
    else:
        i = int(prev_context['selected_outfit']) - 1
        if prev_context['search_type'] == 'image':
            i = int(
                prev_context['image_query_result_index']) - SHOW_THIS_MANY + i
            link = prev_context['image_query_result']['images'][i]['pageUrl']
            title = prev_context['image_query_result']['images'][i]['title']
            img_url = prev_context['image_query_result']['images'][i][
                'imageUrl']
            # using a text message to send fitroom results because Kik breaks out links by putting a trailing "/"
            link_message = TextMessage(to=from_user,
                                       chat_id=chat_id,
                                       body=link)


#            link_message = LinkMessage(to=from_user,chat_id=chat_id,url=link,title=title)
        elif prev_context['search_type'] == 'text':

            i = int(
                prev_context['text_query_result_index']) - SHOW_THIS_MANY + i
            img_url = prev_context['text_query_result']['products'][i][
                'image']['sizes']['IPhone']['url']
            link = prev_context['text_query_result']['products'][i]['clickUrl']
            title = prev_context['text_query_result']['products'][i][
                'brandedName']
            link_message = LinkMessage(to=from_user,
                                       chat_id=chat_id,
                                       url=link,
                                       title=title)
        if context['platform'] == 'KIK':
            here = TextMessage(to=from_user,
                               chat_id=chat_id,
                               body="Here ya go:")
            tip = TextMessage(
                to=from_user,
                chat_id=chat_id,
                body=
                "Remember you can search again anytime by sending me a pic ;)")
            tip.keyboards.append(
                SuggestedResponseKeyboard(responses=[
                    TextResponse('See more results'),
                    TextResponse('Search with this pic'),
                    TextResponse('New search')
                ]))
            kik.send_messages([here, link_message, tip])
        elif context['platform'] == 'FB':
            dispatchMessage(context,
                            'link',
                            chat_id,
                            from_user, [link],
                            suggested_responses=[title],
                            extras=[img_url])