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
Return the synonyms of a word, according to the Merriam Webster Thesaurus.
If you’re interested in getting the definition of a word, consider the define
skill.
This skill requires the following secrets to be configured:
apikey
API key from DictionaryAPI.com
Code
import requests
subscription_key = bot.secrets.read(“apikey”)
search_term = bot.arguments
search_url = “https://www.dictionaryapi.com/api/v3/references/thesaurus/json/” + search_term + “?key=” + subscription_key
response = requests.get(search_url)
response.raise_for_status()
search_results = response.json()
# Merriam Webster’s Thesaurus API returns two different data structures,
# depending on the the results.
# If it autocorrects the results, or can’t find an answer, it returns a vector of strings.
# If it finds an exact match, it will return a dictionary with the results.
if len(search_results) > 0:
if type(search_results[0]) == str:
bot.reply(“Did you mean `” + search_results[0] + “`?”)
elif type(search_results[0]) == dict:
meta = search_results[0].get(“meta”)
syns = meta.get(“syns”)
for syn in syns:
bot.reply(“* ” + “, “.join(syn))
else:
bot.reply(“Couldn’t find any synonyms for `” + bot.arguments + “`.”)