StockBot
in package
This class demonstrates a simple Stock Chat Bot using the Yioop ChatBot APIs for Yioop Discussion Groups.
To use this bot: (1) Move this file to some folder of a web server you have access to. Denote by some_url the url of this folder. If you point your browser at this folder you should see a message that begins with: There was a configuration issue with your query. (2) Under STOCK_URL below change the apikey value to your apikey value that you get from https://www.alphavantage.co/ (3) Create a new Yioop User. (4) Under Manage Accounts, click on the lock symbol next to Account Details (5) Check the Bot User check bot, click save. (6) Two form variables should appear: Bot Unique Token and Bot Callback URL. Fill in a value for Bot Unique Token that matches the value set for ACCESS_TOKEN in the code within the StockBot class. Fill in some_url (as defined in step (1)) for the value of Bot Callback URL (7) Add the the user you created in Yioop to the group that you would like the bot to service. Let the name of this user be user_name. (8) When logged into the user_name account you should now see a Bot Story activity in the activity side bar. Click on Bot Story. This activity lets you add patterns that tell your chat bot how to react when it sees various expressions. To demo your bot add the following three patterns: (a) Request Expression: What is your name? Trigger State: 0 Remote Message: Result State: 0 Response: Stockbot This first pattern just says if someone does a query of the form:
Tags
Table of Contents
- ACCESS_TOKEN = "3456"
- Token given when setting up the bot in Yioop for callback requests This bots checks that a request from a Yioop Instance sends a timestamp as well as the hash of this timestamp with the bot_token and post data and that these match the expected values
- STOCK_URL = "https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY" . "&apikey=289TVF6Y8CH12BRD&interval=1min&symbol="
- Url of site that this bot gets stock price from
- SYMBOL_URL = "http://d.yimg.com/autoc.finance.yahoo.com/autoc"
- Url of site that this bot gets ticker symbol from
- TIME_WINDOW = 60
- Number of seconds that the passed timestamp can differ from the current time on the WeatherBot machine.
- checkBotToken() : mixed
- This method is used to check a request that it comes from a site that knows the bot_token in use by this StockBot.
- getStockPrice() : string
- Get stock price information for a ticker symbol
- getSymbol() : string
- Get ticker symbol for a company name
- processRequest() : mixed
- This is the method called to get the StockBot to handle an incoming HTTP request, and echo a stock related message
Constants
ACCESS_TOKEN
Token given when setting up the bot in Yioop for callback requests This bots checks that a request from a Yioop Instance sends a timestamp as well as the hash of this timestamp with the bot_token and post data and that these match the expected values
public
mixed
ACCESS_TOKEN
= "3456"
STOCK_URL
Url of site that this bot gets stock price from
public
mixed
STOCK_URL
= "https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY" . "&apikey=289TVF6Y8CH12BRD&interval=1min&symbol="
SYMBOL_URL
Url of site that this bot gets ticker symbol from
public
mixed
SYMBOL_URL
= "http://d.yimg.com/autoc.finance.yahoo.com/autoc"
TIME_WINDOW
Number of seconds that the passed timestamp can differ from the current time on the WeatherBot machine.
public
mixed
TIME_WINDOW
= 60
Methods
checkBotToken()
This method is used to check a request that it comes from a site that knows the bot_token in use by this StockBot.
public
checkBotToken() : mixed
Return values
mixed —getStockPrice()
Get stock price information for a ticker symbol
public
getStockPrice(string $args) : string
Parameters
- $args : string
-
the value of $args[0] should be the name to get stock price for
Return values
string —stock price information
getSymbol()
Get ticker symbol for a company name
public
getSymbol(array<string|int, mixed> $args) : string
Parameters
- $args : array<string|int, mixed>
-
the value of $args[0] should be the company name to get ticker symbol for
Return values
string —ticker symbol
processRequest()
This is the method called to get the StockBot to handle an incoming HTTP request, and echo a stock related message
public
processRequest() : mixed