Skip to content

Latest commit

 

History

History
153 lines (97 loc) · 3.52 KB

README.rst

File metadata and controls

153 lines (97 loc) · 3.52 KB

Alphabot

pypi_download

images/logo.png
  • Open source python bot to chat with Slack and eventually other platforms like MS Teams.
  • Alphabot is written for Python 3 leveraging asyncio library with async/await patterns.

Installation

git clone https://github.com/mikhail/alphabot.git
cd alphabot
pip install -e .

Example

Alphabot has some support for conversation flow:

Slack

images/example.png

CLI

images/example_cli.png

Running the bot

If you installed alphabot as a python package then simply run it:

alphabot -S alphabot/sample-scripts/  # or...
alphabot -S path/to/your/scripts/
export SLACK_TOKEN=xoxb-YourToken
alphabot --engine slack -S path/to your/scripts/

API

Function decorators

on_start

@bot.on_start()
def some_command():
    # This command will execute whenever a bot starts

on

Generic event matcher. Useful for things that aren't chat-initiated, like people joining a room, emoji events, etc...

This command will get executed when an event is received with key type and value "something"

@bot.on(type="something")
def some_command(event: dict):
    # event contents depend on the event. For slack - https://api.slack.com/events-api#receiving_events
    log.debug(event)

add_command

Most common decorator - executes when the listener sees the regex. If direct is set to True then this will only trigger if the message is sent in a DM or if the message begins with @<bot name>

@bot.add_command('regex here', direct=False)
def normal_command(message: Chat):
    await message.reply('Regex was matched!')

learn

WIP - Uses NaiveBayesClassifier to do some primitive language learning.

@bot.learn(['Print seven', 'What is your lucky number', 'Give me a number between six and eight'])
def text_match_command(message: Chat):
    await message.reply('Seven!')

on_schedule

year (int|str) - 4-digit year month (int|str) - month (1-12) day (int|str) - day of the (1-31) week (int|str) - ISO week (1-53) day_of_week (int|str) - number or name of weekday (0-6 or mon,tue,wed,thu,fri,sat,sun) hour (int|str) - hour (0-23) minute (int|str) - minute (0-59) second (int|str) - second (0-59) start_date (datetime|str) - earliest possible date/time to trigger on (inclusive) end_date (datetime|str) - latest possible date/time to trigger on (inclusive) timezone (datetime.tzinfo|str) - time zone to use for the date/time calculations (defaults to scheduler timezone)
@bot.on_schedule(minute=0)
def on_the_hour():
    channel = bot.get_channel(name='hourly')
    await channel.send('The time has come!')

Bot functions

api

bot.api(method: str, params: dict)

send

bot.send(text, to, extra)

get_channel

bot.get_channel(**kwargs)