示例#1
0
    def bot_send_attachment(self,
                            user_model,
                            file_url,
                            content_type,
                            keyboard=None):

        if content_type and content_type.startswith('image'):
            message = PictureMessage(to=user_model.conversation_id,
                                     pic_url=file_url)
            if keyboard:
                message.keyboards.append(keyboard)

            self._service.send_messages([message])
            return

        if content_type and content_type.startswith('video'):
            message = VideoMessage(to=user_model.conversation_id,
                                   video_url=file_url)
            if keyboard:
                message.keyboards.append(keyboard)

            self._service.send_messages([message])
            return

        raise Exception('No compatility')
    def test_video_message_incoming(self):
        message = VideoMessage.from_json({
            'from': 'aleem',
            'participants': ['aleem'],
            'mention': None,
            'chatId': 'c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2',
            'videoUrl': 'http://foo.bar/vid',
            'muted': False,
            'autoplay': True,
            'loop': False,
            'attribution': {
                'name': 'Webpage',
                'iconUrl': 'http://foo.bar/icon'
            },
            'id': '8e7fc0ad-36aa-43dd-8c5f-e72f5f2ed7e0',
            'timestamp': 1458336131,
            'readReceiptRequested': True,
            'chatType': 'direct'
        })

        self.assertEqual(message.from_user, 'aleem')
        self.assertEqual(message.participants, ['aleem'])
        self.assertIsNone(message.mention)
        self.assertEqual(message.chat_id, 'c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2')
        self.assertEqual(message.video_url, 'http://foo.bar/vid')
        self.assertIs(False, message.muted)
        self.assertIs(True, message.autoplay)
        self.assertIs(False, message.loop)
        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.chat_type, 'direct')
        self.assertEqual(message.timestamp, 1458336131)
        self.assertIs(True, message.read_receipt_requested)
示例#3
0
 def test_video_message(self):
     message = VideoMessage(video_url='http://foo.bar/vid',
                            to='aleem').to_json()
     self.assertEqual(message, {
         'type': 'video',
         'to': 'aleem',
         'videoUrl': 'http://foo.bar/vid'
     })
示例#4
0
    def test_video_message_preset_attribution(self):
        message = VideoMessage(video_url='http://foo.bar/vid',
                               attribution=PresetAttributions.GALLERY,
                               to='aleem').to_json()

        self.assertEqual(
            message, {
                'type': 'video',
                'to': 'aleem',
                'videoUrl': 'http://foo.bar/vid',
                'attribution': 'gallery'
            })
示例#5
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
            })
示例#6
0
    def bot_send_attachment(self,
                            user_model,
                            file_url,
                            file_type,
                            keyboard=None):

        if file_type and file_type.startswith('image'):
            return self._service.send_messages(
                user_model.conversation_id, [PictureMessage(media=file_url)])

        if file_type and file_type.startswith('video'):
            return self._service.send_messages(user_model.conversation_id,
                                               [VideoMessage(media=file_url)])

        if file_type and file_type.startswith('audio'):
            raise Exception

        return self._service.send_messages(user_model.conversation_id,
                                           [FileMessage(media=file_url)])
示例#7
0
文件: app.py 项目: tsharma2/kik-bot
def incoming():
    print('coming in here')
    if not kik.verify_signature(request.headers.get('X-Kik-Signature'),
                                request.get_data()):
        return Response(status=403)

    messages = messages_from_json(request.json['messages'])

    for message in messages:
        if isinstance(message, TextMessage):
            kik.send_messages([
                ####### NEW #######
                VideoMessage(message.from_user,
                             message.chat_id,
                             video_url=giffy(message),
                             loop=True,
                             autoplay=True)
                ###################
            ])

    return Response(status=200)
示例#8
0
def incoming():
    if not kik.verify_signature(request.headers.get('X-Kik-Signature'), request.get_data()):
        return Response(status=403)

    messages = messages_from_json(request.json['messages'])

    for message in messages:
        if isinstance(message, TextMessage):
            if message.body == 'Hi':
                body = 'What\'s the motive?'
                kik.send_messages([
                        VideoMessage(
                            to=message.from_user,
                            chat_id=message.chat_id,
                            video_url=getGiphy.getGiphy('Hello'),
                            autoplay=True,
                            loop=True,
                        ),
                        TextMessage(
                            to=message.from_user,
                            chat_id=message.chat_id,
                            body=body,
                            keyboards=[
                                SuggestedResponseKeyboard(
                                    responses=[
                                        TextResponse('Staying in'),
                                        TextResponse('Going out'),
                                    ]
                                )
                            ]
                        )
                    ])
                message = TextResponse

        if isinstance(message, TextMessage):
            if message.body == 'Going out':
                body = 'What day though?'
                kik.send_messages([
                        TextMessage(
                            to=message.from_user,
                            chat_id=message.chat_id,
                            body=body,
                            keyboards=[
                                SuggestedResponseKeyboard(
                                    responses=[
                                        TextResponse('Sunday'),
                                        TextResponse('Monday'),
                                        TextResponse('Tuesday'),
                                        TextResponse('Wednesday'),
                                        TextResponse('Thursday'),
                                        TextResponse('Friday'),
                                        TextResponse('Saturday'),
                                    ]
                                )
                            ]
                        )
                    ])
                message = TextResponse

        if isinstance(message, TextMessage):
            if message.body == 'Friday':
                body = ('This is what\'s gucci tonight:\nChainsaw: $3 shots\nEthel\'s: $8 for 1.5lbs wings')
                kik.send_messages([
                        TextMessage(
                            to=message.from_user,
                            chat_id=message.chat_id,
                            body=body,
                            keyboards=[
                                SuggestedResponseKeyboard(
                                    responses=[
                                        TextResponse('Chainsaw'),
                                        TextResponse('Ethel\'s'),
                                    ]
                                )
                            ]
                        )
                    ])
                message = TextReponse

        if isinstance(message, TextMessage):
            if message.body == 'Chainsaw':







        return Response(status=200)
示例#9
0
def incoming():
    if not kik.verify_signature(request.headers.get('X-Kik-Signature'), request.get_data()):
        return Response(status=403)

    messages = messages_from_json(request.json['messages'])

    for message in messages:
        if isinstance(message, TextMessage):
            if message.body == 'Hi':
                body = 'What\'s the motive?'
                kik.send_messages([
                        VideoMessage(
                            to=message.from_user,
                            chat_id=message.chat_id,
                            video_url=getGiphy.getGiphy('Hello'),
                            autoplay=True,
                            loop=True,
                        ),
                        TextMessage(
                            to=message.from_user,
                            chat_id=message.chat_id,
                            body=body,
                            keyboards=[
                                SuggestedResponseKeyboard(
                                    responses=[
                                        TextResponse('Staying in'),
                                        TextResponse('Going out'),
                                    ]
                                )
                            ]
                        )
                    ])
                message = TextResponse

        if isinstance(message, TextMessage):
            if message.body == 'Going out':
                body = 'What day though?'
                kik.send_messages([
                        TextMessage(
                            to=message.from_user,
                            chat_id=message.chat_id,
                            body=body,
                            keyboards=[
                                SuggestedResponseKeyboard(
                                    responses=[
                                        TextResponse('Sunday'),
                                        TextResponse('Monday'),
                                        TextResponse('Tuesday'),
                                        TextResponse('Wednesday'),
                                        TextResponse('Thursday'),
                                        TextResponse('Friday'),
                                        TextResponse('Saturday'),
                                    ]
                                )
                            ]
                        )
                    ])
                message = TextResponse

        if isinstance(message, TextMessage):
            if message.body == 'Friday':
                body = ('This is what\'s gucci tonight:\nChainsaw: $3 shots\nEthel\'s: $8 for 1.5lbs wings')
                kik.send_messages([
                        TextMessage(
                            to=message.from_user,
                            chat_id=message.chat_id,
                            body=body,
                            keyboards=[
                                SuggestedResponseKeyboard(
                                    responses=[
                                        TextResponse('Chainsaw'),
                                        TextResponse('Ethel\'s'),
                                    ]
                                )
                            ]
                        )
                    ])
                message = TextResponse

        if isinstance(message, TextMessage):
            if message.body == 'Chainsaw':
                kik.send_messages([
                        PictureMessage(
                            to=message.from_user,
                            chat_id=message.chat_id,
                            pic_url='http://thecord.ca/wp-content/uploads/2014/09/Chainsaw-Heather-Davidson.jpg',
                        ),
                        TextMessage(
                            to=message.from_user,
                            chat_id=message.chat_id,
                            body='Address: 28 King St N,\n Waterloo, ON N2J 2W6\nPhone:(519) 954-8660'
                        )
                ])

        return Response(status=200)