Last active
March 17, 2017 23:53
-
-
Save malaikannan/0778c1a2aeb696d3becfa803ec3d8f38 to your computer and use it in GitHub Desktop.
Content for the Currency Converter Bot in the tutorial video here: https://www.youtube.com/watch?v=9cDtY_IH_Do&feature=youtu.be
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
USER INPUT NODE | |
Welcome message: Hi! I can help you convert from one currency type to another. | |
TOPIC SELECTOR NODE | |
Greeting: | |
Hello | |
Hi | |
Greetings | |
What do you do? | |
What is your function? | |
Tell me about yourself | |
Convert Currency: | |
Convert 100 USD to INR | |
How many AUD is 1800 JPY? | |
What is 1100 GBP in CAD? | |
3 CZK in HKD | |
546 NOK to NZD | |
Convert from 76 USD to INR | |
Convert to SEK | |
Convert from INR | |
Convert 100 AUD | |
Convert SEK | |
How much is 12355 NZD in JPY? | |
Change 74 INR to USD | |
How many CZK can I get from 842 HKD? | |
ENTITY EXTRACTOR NODE (following convert_currency_topic) | |
Currencyvalue | |
Currencyfrom | |
Currencyto | |
ENTITY CHECKER NODE | |
none missing | |
Currencyvalue missing | |
Currencyfrom missing | |
Currencyto missing | |
RESPONSE NODES (if an entity is missing or was ambiguous) | |
I'm not sure - how many (numerical) units would you like to convert? | |
I'm not sure - what currency would you like to convert from? | |
I'm not sure - what currency would you like to convert to? | |
CODE SNIPPET NODE (to convert lowercase symbols to uppercase) | |
def lambda_handler(event, context): | |
return_json = {} | |
currencyfrom_uppercase = str(event["currencyfrom"]) | |
currencyto_uppercase = str(event["currencyto"]) | |
return_json["currencyfrom_uppercase"] = currencyfrom_uppercase.upper() | |
return_json["currencyto_uppercase"] = currencyto_uppercase.upper() | |
return return_json | |
GENERAL API NODE (to get the conversion rate for 1 unit of from_currency) | |
API url: http://api.fixer.io/latest | |
symbols: [currencyfrom_uppercase] | |
base: [currencyto_uppercase] | |
CODE SNIPPET NODE (to multiply conversion rate with from_value) | |
def lambda_handler(event, context): | |
# A dictionary that will contain everything we need | |
return_json = {} | |
# Get today's date from API | |
return_json["date_from_api"] = event["date"] | |
return_json["from_currency_api"] = event["base"] | |
return_json["from_currency_value"] = float(event["currencyvalue"]) | |
currencyvalue = float(event["currencyvalue"]) | |
rates = event["rates"] | |
for key, value in rates.iteritems(): | |
return_json["to_currency_from_api"] = str(key) | |
return_json["to_currency_value_from_api"] = str(float(value) * currencyvalue) | |
return return_json | |
RESPONSE NODE (upon calling the API and executing code) | |
On [date_from_api] , [from_currency_value] [from_currency_api] is [to_currency_value_from_api] [to_currency_from_api] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment