Google Custom Search results with Slack slash command
It’s a very simple tool that answers requests with Google Custom Search response using also some parsed parameters.
Response is JSON formatted to be used on Slack as Slash command letting users make a quick in-channel google search, or display images/gifs.
By default, this tool returns one image as response, so it can be used to spice the conversation with some memes/etc.
It parses commands provided after hashtags (full list of them lower in this doc), so by adding #link #multi
in beginning of your query you can get first ten results from google.
There are many other ways to use this, and you can easily configure default behavior.
Also, by configuring the CSE itself you can limit searches to one site, or make results from certain site priority/blocked, the possibilities are endless.
#one
- get one result (default)#multi
- get multiple results (10 by default)#[number]
- get [number] result of the search (or if multiple results - start with this number)#link
- get result as standard link#image
- get result as an image (default)#gif
- get result as an GIF image#gray
/ #mono
- search only for images: grayscale / black&white#priv
- display results only for you#pub
- display results public in conversation (default)You can of course join commands, so /xyz #multi #20 #link best cars
gives you list of ten links of “best cars” starting from 20 result.
Every text before or between commands is ignored
/cse not #image working #one but this is
will be searching for “but this is” with one image result
Order of commands is important
/cse #multi #link #gray cats
will return Image results, as last parameter forces it
php composer.phar update
to get required librariessrc/Config.php.dist
to 'your_slack_slash_command_token'
src/Config.php.dist
as value in 'your_google_dev_key'
src/Config.php.dist
as value in 'your_google_custom_search_key'
Config.php
It should work after that, you can of course modify CSE settings to your requirements, like results only from one site, keywords, etc.
The slash command itself is customizable, so you can name it as you wish and add proper description.
Test it with /yourcommand your google query
on Slack
If somethings wrong, you can debug it by running app in console and use first parameter as the query, like php index.php "your google query"
If something still doesn’t work, or you noticed a bad thing, create new issue
Any feedback or code contribution that is useful is welcome.
Current TODO’s are:
in_channel
like #pub
and #priv
Project released under the MIT license. See the LICENSE file for more information.