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 aMailContextobject.on_send: Triggered when an email is sent. The parameter is aMailContextobject.on_command: Triggered when a command is triggered. The parameter is aMailContextobject.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: ASenderobject.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.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file and_eggs-0.0.7-py3-none-any.whl.
File metadata
- Download URL: and_eggs-0.0.7-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/3.8.1 pkginfo/1.8.2 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c6a5c7a7e6b1fae7e766e95aa6a18748c973f1e970d955bd793836a867e165b0
|
|
| MD5 |
9918a84947e89e198b8d7b4dc07286b4
|
|
| BLAKE2b-256 |
707c21fb9cd942139002b3cfbfeae0d5eaaaeba31f6e84b73188dd033768ebd0
|