这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@harshitdx29
Copy link
Contributor

@harshitdx29 harshitdx29 commented Dec 31, 2016

News bot for handling requests of type:
-latest news
-news
-world news

@swapagarwal
Copy link
Owner

@harshitdx29 The overall structure looks good! We would need to add attribution also, right?
Regarding the changes you made to GenericTemplate, are you sure description is supported? I couldn't find it here: https://developers.facebook.com/docs/messenger-platform/send-api-reference/generic-template

Copy link
Owner

@swapagarwal swapagarwal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of my quickest reviews! Awesome work, man. 😄

import requests
import config
import os
import json
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

required?


NEWS_API_KEY = os.environ.get('NEWS_API_KEY', config.NEWS_API_KEY)

def process(input, entities):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are not using entities, we can initialize it to None to signify that.

try:
r = requests.get('https://newsapi.org/v1/articles?source=' + source + '&apiKey=' + NEWS_API_KEY)
data = r.json()
assert(len(data["articles"])>0)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spacing around >

title = article['title']
description = article['description']
url = article['url']
template.add_element(title= title, item_url= url, description= description)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove extra space after =

error_message += '\nPlease ask me something else, like:'
error_message += '\n - latest news'
error_message += '\n - world news'
error_message += '\n - news'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

align - with above lines

BUTTON_TITLE_CHARACTER_LIMIT = 20
BUTTON_LIMIT = 3
ELEMENTS_LIMIT = 10
DESCRIPTION_CHARACTER_LIMIT = 160
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

source?

def add_element(self, title='', description='', item_url='', image_url='', subtitle='', buttons=[]):
element = {}
element['title'] = title[:TITLE_CHARACTER_LIMIT]
element['description'] = description[:DESCRIPTION_CHARACTER_LIMIT]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to check if messenger supports this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My Understanding was that GenericTemplate is something we have written as a wrapper for formatting the output we are generating for each module. Can you please tell me about it?

Also, I din't understand the meaning of adding attribution.

Would be great if you could please help with the above doubts :)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, messenger has some templates that it supports. I've created classes mapping those so that you only have to create a object with the required data, and the rest is taken care of (formatting the data as you see while interacting with the bot). The Generic Template is here: https://developers.facebook.com/docs/messenger-platform/send-api-reference/generic-template
As we are using third-party APIs for data, most of them are free to use but require us to add something like 'Powered by NewsAPI'. This check ensures that it's not our data to show, and we're just serving the data. This helps them gain audience. See the book / weather modules for reference.

@harshitdx29
Copy link
Contributor Author

Review changes done:
Majorly

  1. Attribution was added as a button
  2. Description was replaced by subtitle

@harshitdx29
Copy link
Contributor Author

Good to go ? 😆

@swapagarwal swapagarwal merged commit 59beb1c into swapagarwal:master Jan 3, 2017
@swapagarwal
Copy link
Owner

Thanks @harshitdx29! 👍

@harshitdx29
Copy link
Contributor Author

Thanks @swapagarwal 👍 Should i update the README for features in a separate PR?

@swapagarwal
Copy link
Owner

I have some backlog in README updation which I plan to do on weekend. 😇

@swapagarwal swapagarwal mentioned this pull request Jan 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants