示例#1
0
    def test_message_inequality(self):
        message1 = PictureMessage(
            pic_url='http://foo.bar/image',
            to='aleem',
            mention='anotherbot',
            chat_id=
            'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855',
            keyboards=[
                SuggestedResponseKeyboard(hidden=True,
                                          responses=[TextResponse('Foo')])
            ],
            attribution=CustomAttribution(name='Foobar Not The Same'),
            delay=100)

        message2 = PictureMessage(
            pic_url='http://foo.bar/image',
            to='aleem',
            mention='anotherbot',
            chat_id=
            'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855',
            keyboards=[
                SuggestedResponseKeyboard(hidden=True,
                                          responses=[TextResponse('Foo')])
            ],
            attribution=CustomAttribution(name='Foobar'),
            delay=100)

        self.assertNotEqual(message1, message2)
示例#2
0
    def send_image_response(to, chat_id, album_art, album, keyboards=None):
        message = PictureMessage(to=to, chat_id=chat_id, pic_url=album_art)

        message.attribution = CustomAttribution(name=album)

        if keyboards:
            message.keyboards.append(
                SuggestedResponseKeyboard(hidden=True, responses=keyboards))

        kik.send_messages([message])
示例#3
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
            })
示例#4
0
    def test_video_message_complete(self):
        message = VideoMessage(
            video_url='http://foo.bar/vid',
            to='aleem',
            mention='anotherbot',
            chat_id=
            'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855',
            autoplay=True,
            muted=True,
            loop=True,
            no_save=True,
            keyboards=[
                SuggestedResponseKeyboard(hidden=True,
                                          responses=[TextResponse('Foo')])
            ],
            attribution=CustomAttribution(name='Foobar'),
            delay=100).to_json()

        self.assertEqual(
            message, {
                'type':
                'video',
                'to':
                'aleem',
                'mention':
                'anotherbot',
                'chatId':
                'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855',
                'videoUrl':
                'http://foo.bar/vid',
                'muted':
                True,
                'loop':
                True,
                'autoplay':
                True,
                'noSave':
                True,
                'keyboards': [{
                    'type': 'suggested',
                    'hidden': True,
                    'responses': [{
                        'type': 'text',
                        'body': 'Foo'
                    }]
                }],
                'attribution': {
                    'name': 'Foobar'
                },
                'delay':
                100
            })
示例#5
0
def showShopStyleResults(chat_id, from_user, context):
    api_json = context['text_query_result']
    result_image_urls = [
        value['image']['sizes']['IPhone']['url']
        for value in api_json['products']
    ]

    text_query_result_index = int(context['text_query_result_index'])
    i = 0
    if text_query_result_index + SHOW_THIS_MANY >= len(result_image_urls):
        message = "Well, maybe not. Gosh, you're hard to please :/ Try sending me back a pic of something I've showed you already to keep looking."
        sendSuggestedResponseHowTo(chat_id, from_user, message, context)
        return api_json
    urls = []
    titles = []
    for an_image in result_image_urls[text_query_result_index:]:
        if i >= SHOW_THIS_MANY:
            break
        title = api_json['products'][i]['brandedName']
        urls.append(an_image)
        titles.append(title)
        if context['platform'] == 'KIK':
            picture_message = PictureMessage(to=from_user,
                                             chat_id=chat_id,
                                             pic_url=an_image)
            picture_message.attribution = CustomAttribution(name=title)
            kik.send_messages([picture_message])

        i += 1
    if context['platform'] == 'FB':
        dispatchMessage(context,
                        'image',
                        chat_id,
                        from_user,
                        urls,
                        suggested_responses=titles)
    context[
        'text_query_result_index'] = i + text_query_result_index  # remember which results we've showed
    context['text_query_result'] = api_json
    storeContext(chat_id, from_user, context, action='showShopStyleResults')
    if context['platform'] == 'KIK':
        selectAnImageMsg(chat_id, context)
        return api_json
示例#6
0
    def test_picture_message_complete(self):
        message = PictureMessage(
            pic_url='http://foo.bar/image',
            to='aleem',
            mention='anotherbot',
            chat_id=
            'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855',
            keyboards=[
                SuggestedResponseKeyboard(hidden=True,
                                          responses=[TextResponse('Foo')])
            ],
            attribution=CustomAttribution(name='Foobar'),
            delay=100).to_json()

        self.assertEqual(
            message, {
                'type':
                'picture',
                'to':
                'aleem',
                'mention':
                'anotherbot',
                'chatId':
                'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855',
                'picUrl':
                'http://foo.bar/image',
                'keyboards': [{
                    'type': 'suggested',
                    'hidden': True,
                    'responses': [{
                        'type': 'text',
                        'body': 'Foo'
                    }]
                }],
                'attribution': {
                    'name': 'Foobar'
                },
                'delay':
                100
            })