This is a simple OpenWhisk serverless app written in PHP that will tell you what time it is where your friend lives.
Screenshot of FTime in Slack
These action exist:
time: expects to respond to/timein Slack & will return the time for your friend or a city.setTimezone: expects to respond to/settimezonein Slack to store a friend's timezone into CouchDB with their name as the key.listTimezones: will show a list of timezones.findTimeByTimezone: givenplacewhich is a substring of at timezone will return the time for all timezones that match the substring.findFriendTime: givennamewill look up the timezone from CouchDB and then find the time for that timezone usingfindTimeByTimezone.
-
Create
settings.json- start withsettings.json.dist- Edit the information in
settings.jsonto connect to your Slack and Couch DB
- Edit the information in
-
Read the Makefile to see what to do:
make setupto create the packagemaketo build and upload all the actions
As running PHP actions natively doesn't exist outside of a branch), we use ngrok to enable Slack to talk to a local Vagrant install of OpenWhisk
-
Create a Slack App with two slash commands:
/timecommand tohttp://ftime.ngrok.io/api/v1/web/guest/FTime/time/setTimezonecommand tohttp://ftime.ngrok.io/api/v1/web/guest/FTime/setTimezone
-
Run ngrok with command:
ngrok http -subdomain ftime 192.168.33.13:10001 -
seed database:
./seed-data/seed_couchdb.sh
$ curl -k https://192.168.33.13/api/v1/web/guest/FTime/findTimeByTimezone?place=Auckland | jq -S
{
"pattern": "Auckland",
"times": [
{
"time": "08:55:26",
"timezone": "Pacific/Auckland"
}
]
}
$ curl -k https://192.168.33.13/api/v1/web/guest/FTime/time?text=Sara | jq -S
{
"response_type": "in_channel",
"text": "It's currently 6:52am for Sara."
}
$ curl -k https://192.168.33.13/api/v1/web/guest/FTime/setTimezone?text=Andrew%20Azores | jq -S
{
"response_type": "in_channel",
"text": "Andrew now has a time zone of Atlantic/Azores"
}
