Time based Greetings in Slack
I spend a lot of time communicating with some remote teams. Most of the conversation is done in Slack. Recently I thought of a cool way to implement TextExpander and Slack.
When I start the conversation, I usually do it first thing in the morning with 'Good Morning Champion.' The problem is that in the remote offices it could be afternoon or evening so the greeting is a bit strange. That's when I thought that TextExpander could make the greeting more friendly.
I created several location base snippets that would enter in the proper time greetings based on their location.
Real World Example
There is a snippet in my library for 'in.hello' and this will automatically display the correct greetings when I am talking to my India team in chat. So if it's night time, it would say 'Good Evening Champion' and if it's before 6 pm their time, 'Good Afternoon Champion.' I have sfo.hello, Japan.hello and Korea.hello.
Now I will always say the correct greetings and not have to think about it.
This is the PHP code that I use to get that done:
#!/usr/bin/php <?php date_default_timezone_set('Indian/Mauritius'); function greeting(){ $timeOfDay = date('H'); if($timeOfDay > '17'){ return 'Good evening Champion. '; } else if ($timeOfDay > '12'){ return 'Good afternoon Champion. '; } else { return 'Good morning Champion. '; } } echo greeting(); ?>
I used the PHP Date functionality and not the built in date tools in TextExpander because of portability. I can travel to any time zone and not have to worry about what my system clock says, the greeting will always be correct.