This handler will allow Alice to look up random images on Google Images
If available in Hex, the package can be installed as:
- Add
alice_google_images
to your list of dependencies inmix.exs
:
```elixir
defp deps do
[
{:websocket_client, github: "jeremyong/websocket_client"},
{:alice, "~> 0.3"},
{:alice_google_images, "~> 0.1"}
]
end
```
- Add the handler to your list of registered handlers in
mix.exs
:
```elixir
def application do
[applications: [:alice],
mod: {
Alice, [Alice.Handlers.GoogleImages, ...]}]
end
```
Google no longer offers an unregistered image search API. You must set up a Google Custom Search API.
The Custom Search API provides up to 100 search queries per day for free. If you need more than that you'll have to pay.
- Create a CSE via these instructions.
- To simulate the old behavior: select "Search the entire web but emphasize included sites" in 'Sites to Search'
- Give it any site on creation, and then remove it when it's selected, unless you want to emphasize that site(s).
- Turn on images in Edit Search Engine > Setup > Basic > Image Search
- Get the CSE ID in Edit Search Engine > Setup > Basic > Details (via these instructions)
- Get the CSE KEY here https://code.google.com/apis/console
- You will need a project, you may reuse an existing one, or create a new one
- Select the project
- Goto the API manager and create a server credential and use the key from that credential
- Enable Custom Search API
- https://console.developers.google.com
- Select "Enable APIs and get credentials like keys" in your new project
- Click "Custom Search API"
- Click the button "Enable API"
- Update your conf (and your modules if necessary)
In your bot's config.exs
:
config :alice_google_images,
cse_id: System.get_env("GOOGLE_CSE_ID"),
cse_token: System.get_env("GOOGLE_CSE_TOKEN"),
safe_search_level: :medium # other possible values are :high or :off
Use @alice help
for more information.