What is Opsdroid?

Aayush Pandey
2 min readJul 8, 2021

--

Photo by Markus Spiske on Unsplash

Automate boring things!

Introducing opsdroid, a Python 3 chat-ops bot. An open source chatbot framework written in Python. It is designed to be extendable, scalable and simple.

This framework is designed to take events from chat services and other sources and execute Python functions (skills) based on their contents. Those functions can be anything you like, from simple conversational responses to running complex tasks. The true power of this project is to act as a glue library to bring the multitude of natural language APIs, chat services and third-party APIs together.

Open source. Simple to install. Easy to extend.

pip3 install opsdroid

opsdroid

A single framework- Open Source, Extendable, Scalable and Simple

Photo by KOBU Agency on Unsplash

Designed to take messages from chat services and execute Python functions (skills) based on their contents.

All your needs in one single framework.

1. Connectors

Connector modules transfer messages between opsdroid and a particular chat service.

2. Databases

Database modules allow opsdroid to persist information in a database of your choice.

3. Parsers

Parsers/Matchers modules gather meaning of what was said and match a skill.

4. Skills

Skills are what makes opsdroid tick. They define how opsdroid should respond and what actions to take.

Making Skill word of a day using Opsdroid

Requirements

None.

Configuration

None.

Usage

What's the word of the day?

Get the word of the day. This runs automatically at 09:30.

user: what’s the word of the day?

opsdroid: Word of the day oecumene | ecumene, n.

The inhabited or civilized world, spec. that known to the ancient Greeks

import logging
import random
import aiohttp
import feedparser
from opsdroid.matchers import match_regex, match_crontab
from opsdroid.message import Message
_LOGGER = logging.getLogger(__name__)
_OED_WOD_BASE_URL = "http://www.oed.com/rss/wordoftheday"
async def get_feed():
async with aiohttp.ClientSession() as session:
async with session.get(_OED_WOD_BASE_URL) as resp:
feed = feedparser.parse(await resp.text())
return feed
@match_regex(r'.*word of the day.*')
@match_crontab('30 09 * * 1-5')
async def word_of_the_day(opsdroid, config, message):
if message is None:
message = Message("",
None,
config.get("room", opsdroid.default_connector.default_room),
opsdroid.default_connector)
intro = random.choice([
"Here's today's word of the day",
"Here's the OED word of the day",
"Why not try and use this word today",
"Today's goal, say this word to a stranger"
])
feed = await get_feed()
word = feed["entries"][0]["title"]
link = feed["entries"][0]["link"]
definition = ".".join(feed["entries"][0]["summary"].split(".")[1:]).strip()
response = "{}\n> *{}*\n> {}\n> {}".format(intro, word, definition, link)
await message.respond(response)

--

--