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/time
in Slack & will return the time for your friend or a city.setTimezone
: expects to respond to/settimezone
in Slack to store a friend's timezone into CouchDB with their name as the key.listTimezones
: will show a list of timezones.findTimeByTimezone
: givenplace
which is a substring of at timezone will return the time for all timezones that match the substring.findFriendTime
: givenname
will 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.json
to connect to your Slack and Couch DB
- Edit the information in
-
Read the Makefile to see what to do:
make setup
to create the packagemake
to 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:
/time
command tohttp://ftime.ngrok.io/api/v1/web/guest/FTime/time
/setTimezone
command 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"
}