-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from botstory/feature/based-on-rss-bot
Feature/based on rss bot
- Loading branch information
Showing
16 changed files
with
274 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM python:3.5 | ||
FROM python:3.6 | ||
|
||
ENV PYTHONUNBUFFERED 1 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import os | ||
|
||
print('os.path.dirname(os.path.realpath(__file__))') | ||
print(os.path.dirname(os.path.realpath(__file__))) | ||
|
||
with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'version.txt')) as version_file: | ||
__version__ = version_file.read().strip() | ||
|
||
# some general information about this bot | ||
|
||
BOT_ID = 'boilerplatebot' | ||
|
||
BOT_NAME = 'Boilerplate bot' | ||
|
||
GITHUB_URL = 'https://github.com/botstory/boilerplate-bot/' | ||
|
||
SHORT_INTO = 'Hello dear {{user_first_name}}!\n' \ | ||
'I\'m ' + BOT_NAME + ' assistant based on BotStory framework.\n' \ | ||
'I\'m here to help you to get boilerplate and make new bot from it.\n' | ||
|
||
SHORT_HELP = SHORT_INTO + \ | ||
'\n' \ | ||
'All sources could be find here:\n' \ | ||
':package: ' + GITHUB_URL + ',\n' \ | ||
'feedback and contribution are welcomed!' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import botstory | ||
from botstory.integrations import aiohttp, fb, mongodb | ||
from botstory.integrations.ga import tracker | ||
import logging | ||
import os | ||
|
||
from boilerplate import BOT_ID, BOT_NAME, GITHUB_URL, SHORT_INTO, stories | ||
|
||
|
||
# TODO: here should be all documents | ||
DOCUMENTS = () | ||
|
||
logger = logging.getLogger(BOT_NAME) | ||
logger.setLevel(logging.DEBUG) | ||
logging.basicConfig(level=logging.DEBUG) | ||
|
||
|
||
class Bot: | ||
def __init__(self): | ||
self.story = botstory.Story() | ||
|
||
def init(self, auto_start, fake_http_session): | ||
self.story.use(fb.FBInterface( | ||
# will show on initial screen | ||
greeting_text=SHORT_INTO, | ||
|
||
# you should get on admin panel for the Messenger Product in Token Generation section | ||
page_access_token=os.environ.get('FB_ACCESS_TOKEN', 'TEST_TOKEN'), | ||
# menu of the bot that user has access all the time | ||
persistent_menu=[ | ||
{ | ||
'type': 'postback', | ||
'title': 'Hi!', | ||
'payload': 'ABOUT_ME', | ||
}, { | ||
'type': 'nested', | ||
'title': 'Help', | ||
'call_to_actions': [ | ||
{ | ||
'type': 'web_url', | ||
'title': 'Source Code', | ||
'url': GITHUB_URL, | ||
}, { | ||
'type': 'postback', | ||
'title': 'About', | ||
'payload': 'ABOUT_ME', | ||
}, | ||
], | ||
}, | ||
], | ||
# should be the same as in admin panel for the Webhook Product | ||
webhook_url='/webhook{}'.format(os.environ.get('FB_WEBHOOK_URL_SECRET_PART', '')), | ||
webhook_token=os.environ.get('FB_WEBHOOK_TOKEN', None), | ||
)) | ||
|
||
# Interface for HTTP | ||
http = self.story.use(aiohttp.AioHttpInterface( | ||
port=int(os.environ.get('PORT', 8080)), | ||
auto_start=auto_start, | ||
)) | ||
|
||
# User and Session storage | ||
db = self.story.use(mongodb.MongodbInterface( | ||
uri=os.environ.get('MONGODB_URI', 'mongo'), | ||
db_name=os.environ.get('MONGODB_DB_NAME', BOT_ID), | ||
)) | ||
|
||
self.story.use(tracker.GAStatistics( | ||
tracking_id=os.environ.get('GA_ID'), | ||
)) | ||
|
||
# for test purpose | ||
http.session = fake_http_session | ||
|
||
stories.setup(self.story) | ||
return http, db | ||
|
||
async def setup(self, fake_http_session=None): | ||
logger.info('# setup') | ||
self.init(auto_start=False, fake_http_session=fake_http_session) | ||
await self.story.setup() | ||
|
||
async def start(self, auto_start=True, fake_http_session=None): | ||
logger.info('# start') | ||
http, db_integration = self.init(auto_start, fake_http_session) | ||
await self.story.setup() | ||
await self.story.start() | ||
for document in DOCUMENTS: | ||
document.setup(db_integration.db) | ||
return http.app | ||
|
||
async def stop(self): | ||
logger.info('# stop') | ||
await self.story.stop() | ||
self.story.clear() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from boilerplate.stories.greetings import greeting_stories | ||
from boilerplate.stories.help import help_stories | ||
from boilerplate.stories.query import query_stories | ||
|
||
story_modules = ( | ||
greeting_stories, | ||
query_stories, | ||
|
||
# last hope :) | ||
# if we haven't handle message before, | ||
# then show help message to user | ||
help_stories, | ||
) | ||
|
||
|
||
def setup(story): | ||
for m in story_modules: | ||
m.setup(story) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import logging | ||
|
||
import boilerplate | ||
from boilerplate.utils import inject_first_name | ||
# from boilerplate.query import query_stories | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def setup(story): | ||
@story.on_start() | ||
def on_start_story(): | ||
@story.part() | ||
async def greet(ctx): | ||
await story.say(inject_first_name(boilerplate.SHORT_INTO, ctx['user']), | ||
user=ctx['user']) | ||
await story.say('For example: <give one random recommendation from bot + quick_replies>', | ||
user=ctx['user']) |
Empty file.
Oops, something went wrong.