GMail Bot API
Project description
AndEggs
AndEggs is a Python library that allows you to create an email bot using Gmail's API.
Simple Documentation
Client Class
The Client
class will be the main entry point of your program.
Create a Client
First, create a new client by calling the Client
constructor:
>>> from andeggs import Client
>>> client = Client('CommandPrefix')
Then, you can use the Client
object to interact with Gmail's API.
Creating a Command
To create a command, you should create an asynchronous function that will be called when the command is triggered.
It should take in a MailContext
object as its only parameter. This object contains all the information about the email that triggered the command.
To turn it into a command, use the Client.command
decorator:
>>> @client.command('CommandName')
>>> async def command(context: MailContext):
>>> # Do something
>>> pass
Sending an Email
To send an email, you should use the Client.send
method:
>>> client.send(
>>> to='RecipientEmail',
>>> subject='Subject',
>>> body='Body',
>>> is_html=False,
>>> )
Activating the Client
To activate the client, you should call the Client.run
method:
>>> client.run('youremail', 'yourpassword')
Events
Events are triggered when certain actions happen. Below is a list of the events that can be triggered and their parameters:
on_ready
: Triggered when the client is started.on_message
: Triggered when a new email is received. The parameter is aMailContext
object.on_send
: Triggered when an email is sent. The parameter is aMailContext
object.on_command
: Triggered when a command is triggered. The parameter is aMailContext
object.on_stop
: Triggered when the client is stopped.
Tasks
A task is a function that runs in the background. You can use the Client.task
decorator to create a task:
>>> @client.task(interval=60)
>>> async def task():
>>> # Do something
>>> pass
MailContext
On all of your commands, you will receive a MailContext
object. This object contains all the information about the email that triggered the command.
Attributes
sender
: ASender
object.subject
: The subject of the email.body
: The body of the email.
Sending an Email
You can also send an email using the MailContext.send
method:
>>> context.send(
>>> 'Body',
>>> )
If you want to format your text with html, you should use the MailContext.sendf
method:
>>> context.sendf(
>>> '<p>{}</p>',
>>> 'Body',
>>> )
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.