Last active
September 3, 2016 23:02
-
-
Save hyzhak/b9adcc938abe9bfb4335cf31ef0abbee to your computer and use it in GitHub Desktop.
architecture of stories - stateless and async
This file contains hidden or 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
""" | |
v0.1.0 | |
Bot asks user about destionation of space travelling. | |
- stateful story, it stores context of story (current question) in python interpreter | |
""" | |
@story.once('lets go!') | |
async def async_story(message): | |
dest = await ask_location(message['user'], text='Where do you go?') | |
store_destination(dest['location']) | |
origin = await ask_location(message['user'], text='Where do you now?') | |
store_origin(origin['location']) | |
await tell(message['user'], 'Thanks! Give me a minute I will find you right spaceship!') |
This file contains hidden or 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
""" | |
v0.1.1 | |
Bot asks user about destionation of space travelling. | |
- stateful story, it stores context of story (current question) in python interpreter | |
""" | |
@story.once('lets go!') | |
async def async_story(message): | |
dest = await ask_location(message['user'], text='Where do you go?') | |
store_destination(dest['location']) | |
origin = await ask_location(message['user'], text='Where do you now?') | |
while origin['location'] in ['starts', 'planets]: | |
location = origin['location'] | |
if location == 'stars': | |
#cycle back | |
origin = await ask_location(message['user'], text='Which star do you prefer?', then=receive_destination) | |
elif location == 'planets': | |
#cycle back | |
origin = await ask_location(message['user'], text='Which planet do you prefer?', then=receive_destination) | |
store_origin(origin['location']) | |
await tell(message['user'], 'Thanks! Give me a minute I will find you right spaceship!') |
This file contains hidden or 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
""" | |
v0.2.0 | |
Bot asks user about destionation of space travelling. | |
- stateless story. it stores context of story (current question and results) somewhere (maybe DB) | |
""" | |
@story.once('lets go!') | |
def stateless_story(message): | |
return ask_location(message['user'], text='Where do you go?') | |
@story.than() | |
def than(message): | |
store_destination(message['location']) | |
return ask_location(message['user'], text='Where do you now?') | |
@story.than() | |
def than(message): | |
store_origin(message['location']) | |
return tell(message['user'], 'Thanks! Give me a minute I will find you right spaceship!') |
This file contains hidden or 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
""" | |
v0.2.1 | |
Bot asks user about destionation of space travelling. | |
- stateless story. it stores context of story (current question and results) somewhere (maybe DB) | |
""" | |
@story.on('lets go!') | |
def stateless_story_with_bifurcation(): | |
@story.then() | |
def request_destination(message): | |
return ask_location(message['user'], text='Where do you go?') | |
@story.then() | |
def receive_destination(message): | |
location = message['location]'] | |
if location == 'stars': | |
#cycle back | |
return ask_location(message['user'], text='Which star do you prefer?', then=receive_destination) | |
elif location == 'planets': | |
#cycle back | |
return ask_location(message['user'], text='Which planet do you prefer?', then=receive_destination) | |
elif: | |
return choose_option(top10_planets, | |
text='Here is the most popular places. Maybe you would like to choose one?', | |
then=receive_destination_options) | |
else: | |
store_destination(message['location']) | |
return request_origin(message) | |
@story.then() | |
def receive_destination_options(message): | |
store_destination(message['location']) | |
return request_origin(message) | |
@story.then() | |
def request_origin(message): | |
return ask_location(message['user'], text='Where do you now?', topic='get-origin') | |
@story.then() | |
def receive_origin(message): | |
store_origin(message['location']) | |
return tell(message['user'], 'Thanks! Give me a minute I will find you right spaceship!') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment