Get the dictionary definition of a word
About Abbot
Abbot is a programmable bot that turns your team chat into a shared command center. We handle all the boilerplate of building and running these conmmands so that you can focus on making tools that help you ship faster.
We built Abbot because we saw the power of this style of work (called ChatOps), when we worked at GitHub. ChatOps made it possible for GitHub to work productively without meetings, while globally distributed. We think it’s a pretty great way to work, so we made it easy to use in Slack, Discord, and Microsoft Teams.
You can read more about Abbot here, check out our blog, or take a look at some of the other cool packages available as a one-click install from Abbot’s Package Directory.
README
The define
skill fetches the definition of words from Merriam Webster and displays them in chat. If you’re interested in synonyms of a word, consider using the synonyms
package.
This skill requires the following secrets to be configured:
apikey
DictionaryAPI api key
Code
import requests
subscription_key = bot.secrets.read(“apikey”)
if subscription_key is None:
bot.reply(“This skill needs an API key from https://dictionaryapi.com/. Register for a key there and add it as a secret called ‘apikey’ in the skill.”)
else:
search_term = bot.arguments
search_url = “https://dictionaryapi.com/api/v3/references/collegiate/json/” + search_term + “?key=” + subscription_key
response = requests.get(search_url)
response.raise_for_status()
search_results = response.json()
res = search_results[0]
if type(res) == str:
bot.reply(“Did you mean `” + res + “`?”)
else:
result = res.get(“shortdef”)
out = “* ” + “\n* “.join(result)
bot.reply(out)