Examples
Once you have installed deltachat bindings you need email/password credentials for an IMAP/SMTP account. Delta Chat developers and the CI system use a special URL to create temporary email accounts on testrun.org for testing.
Receiving a Chat message from the command line
Here is a simple bot that:
receives a message and sends back (“echoes”) a message
terminates the bot if the message /quit is sent
# content of echo_and_quit.py
from deltachat import account_hookimpl, run_cmdline
class EchoPlugin:
@account_hookimpl
def ac_incoming_message(self, message):
print("process_incoming message", message)
if message.text.strip() == "/quit":
message.account.shutdown()
else:
# unconditionally accept the chat
message.create_chat()
addr = message.get_sender_contact().addr
if message.is_system_message():
message.chat.send_text(f"echoing system message from {addr}:\n{message}")
else:
text = message.text
message.chat.send_text(f"echoing from {addr}:\n{text}")
@account_hookimpl
def ac_message_delivered(self, message):
print("ac_message_delivered", message)
def main(argv=None):
run_cmdline(argv=argv, account_plugins=[EchoPlugin()])
if __name__ == "__main__":
main()
With this file in your working directory you can run the bot by specifying a database path, an email address and password of a SMTP-IMAP account:
$ cd examples
$ python echo_and_quit.py /tmp/db --email ADDRESS --password PASSWORD
While this process is running you can start sending chat messages to ADDRESS.
Track member additions and removals in a group
Here is a simple bot that:
echoes messages sent to it
tracks if configuration completed
tracks member additions and removals for all chat groups
With this file in your working directory you can run the bot by specifying a database path, an email address and password of a SMTP-IMAP account:
python group_tracking.py --email ADDRESS --password PASSWORD /tmp/db
When this process is running you can start sending chat messages to ADDRESS.
Writing bots for real
The deltabot repository contains a little framework for writing deltachat bots in Python.