rfcarrara / fbmessengerbot

1 stars 0 forks source link

Loop not implemented correctly #1

Open guitmz opened 7 years ago

guitmz commented 7 years ago

In example.py, the loop at line 18 is incorrect. The code in line 22 should be inside this loop but it's outside.

guitmz commented 7 years ago
        for entry in data['entry']:
            recipient_id = entry['messaging'][0]['sender']['id']
            received_text = entry['messaging'][0]['message']['text']

        if received_text == '/hnews':
            message_params = {
                'title': 'Hacker News',
                'subtitle': 'Hacker News Website',
                'item_url': 'https://news.ycombinator.com/',
                'image_url': ''
            }
            return fb.send_link_message(recipient_id, message_params)

should be

        for entry in data['entry']:
            recipient_id = entry['messaging'][0]['sender']['id']
            received_text = entry['messaging'][0]['message']['text']

            if received_text == '/hnews':
                message_params = {
                    'title': 'Hacker News',
                    'subtitle': 'Hacker News Website',
                    'item_url': 'https://news.ycombinator.com/',
                    'image_url': ''
                }
                return fb.send_link_message(recipient_id, message_params)
            else:
                return fb.send_message(recipient_id, 'Would like to receive a random Hacker News? (Type: /hnews)')

I would also not return values here but log them on the stdout instead because if there are multiple entries in data['entry'], the code will stop on the first nevertheless.