How to set up a delta-bot in 6 steps

Do you want to set up your own DeltaChat bot??? It is really easy, read on.

Requisites:

  • An email account for the bot.
  • GNU/Linux 64bit machine (can be installed in other systems but you will need to compile DeltaChat’s core yourself but that isn’t covered in this tutorial)
  • 500MB of RAM or more (a bot with few users use less than 100MB of RAM)
  • Python >=3.6

Steps:

  1. Declare bot address and password (Optional just to make this tutorial easier):
    $ ADDR='bot@example.com'
    $ PASSWORD='myPassword'
    
  2. Create and activate virtual environment (Optional but recommended):
    $ python3 -m venv ~/.venvs/`echo $ADDR|tr "@" "_"`
    $ source ~/.venvs/`echo $ADDR|tr "@" "_"`/bin/activate
    $ pip3 install -U pip wheel
    
  3. Install simplebot:
     $ pip3 install simplebot
    
  4. Install some plugins, for example the simplebot-echo plugin:
     $ pip3 install simplebot-echo
    
  5. Configure bot:
     $ simplebot init $ADDR "$PASSWORD"
    
  6. Start the bot:
     $ simplebot -a $ADDR serve
    

And that is all, now your have your very own delta-bot! go to your DeltaChat app and write a message: /help to your bot’s address to check it is working!

It is very cheap to run a bot, so you can repeat this steps in the same machine with another email account and have several bots, I recommend to have 250-500MB of RAM per bot if it will be a public bot.

For a list of plugins to install in your bot check:

7 Likes

:fireworks::sparkler::confetti_ball::tada: Thanks so much! :tada::confetti_ball::sparkler::fireworks:

1 Like

I have no idea what I’m doing wrong but I can’t run a simplebot on my machine. I’m using Ubuntu 20.04 and I wanted to test simplebot. All I get are the following error messages. When I configure bot (step 6):

“Traceback (most recent call last):
File “[…]/bin/simplebot”, line 8, in
sys.exit(main())
File “[…]/lib/python3.8/site-packages/deltabot/main.py”, line 24, in main
parser.main_run(bot=bot, args=args)
File “[…]/lib/python3.8/site-packages/deltabot/parser.py”, line 87, in main_run
res = args.subcommand_instance.run(bot=bot, args=args, out=out)
File “[…]/lib/python3.8/site-packages/deltabot/builtin/cmdline.py”, line 51, in run
success = bot.perform_configure_address(args.emailaddr, args.password)
File “[…]/lib/python3.8/site-packages/deltabot/bot.py”, line 160, in perform_configure_address
self.account.update_config(dict(
File “[…]/lib/python3.8/site-packages/deltachat/account.py”, line 155, in update_config
self.set_config(key, str(value))
File “[…]/lib/python3.8/site-packages/deltachat/account.py”, line 111, in set_config
self._check_config_key(name)
File “[…]/lib/python3.8/site-packages/deltachat/account.py”, line 78, in _check_config_key
raise KeyError(”{!r} not a valid config key, existing keys: {!r}".format(
KeyError: “‘bot’ not a valid config key, existing keys: [‘addr’, ‘mail_server’, ‘mail_user’, ‘mail_pw’, ‘mail_port’, ‘imap_certificate_checks’, ‘send_server’, ‘send_user’, ‘send_pw’, ‘send_port’, ‘smtp_certificate_checks’, ‘server_flags’, ‘imap_folder’, ‘displayname’, ‘selfstatus’, ‘selfavatar’, ‘bcc_self’, ‘e2ee_enabled’, ‘mdns_enabled’, ‘inbox_watch’, ‘sentbox_watch’, ‘mvbox_watch’, ‘mvbox_move’, ‘show_emails’, ‘media_quality’, ‘key_gen_type’, ‘delete_server_after’, ‘delete_device_after’, ‘save_mime_headers’, ‘configured_addr’, ‘configured_mail_server’, ‘configured_mail_user’, ‘configured_mail_pw’, ‘configured_mail_port’, ‘configured_mail_security’, ‘configured_imap_certificate_checks’, ‘configured_send_server’, ‘configured_send_user’, ‘configured_send_pw’, ‘configured_send_port’, ‘configured_smtp_certificate_checks’, ‘configured_server_flags’, ‘configured_send_security’, ‘configured_e2ee_enabled’, ‘configured_inbox_folder’, ‘configured_mvbox_folder’, ‘configured_sentbox_folder’, ‘configured’, ‘sys.version’, ‘sys.msgsize_max_recommended’, ‘sys.config_keys’, ‘notify_about_wrong_pw’, ‘basic_web_rtc_instance’]”

And later when I start the bot (step 7):

FAIL: account not configured: [full path]/account.db

Btw, I’m using a Mail-In-A-Box instance to run my email but I don’t think it matters here.

You are using an old core, change the dependency to use a core version >= 1.47

as @Simon said, you are using an old version of the deltachat package, run step 3 again, the ‘bot’ configuration was added recently to indicate the account is a bot (it might be used in the future to advertise the account as a bot and show nice “bot” indicators in the Delta Chat clients)

I will update simplebot package to state >=1.40.2 is requred

Just did that, but the error is still there. Perhaps the files up on https://m.devpi.net/dc/master are out-of-date?

I just configured a new bot some minutes ago without any issue, got deltachat-1.40.2 installed from https://m.devpi.net/dc/master,
this smells a lot to a weird issue that happened to me once, try this first:
pip install -U pip

then you can go with:
pip install --pre -U -i https://m.devpi.net/dc/master deltachat

ahhh maybe it is the --pre option!

Yup, that’s it. Now I managed to start the bot. Thank you!

1 Like

great! :tada:
btw, a bit late by now but: welcome to the forum!

Thanks again. Great to be here :vulcan_salute:t2:

OK. I really want to create my own bots for some functions I would like to perform through Delta. But I’m really having problems understanding the steps (not a programmer,) so …

I tried @adbenitez deployment at Heroku here: GitHub - adbenitez/simplebot-www-heroku: SimpleBot Heroku deployment for a web browsing and file downloader bot

I created an email through my Yunohost setup and deployed it as per the instructions as I understood them. However, there is no response from the bot. (I can see my /help emails being sent, but nothing comes back.) Assuming I’m really simple, what should I do next?

My thinking is that if I can learn and understand through the work that someone else has done, that eventually I’ll be able to set up and program my own.

Thanks All!

hi @axe heroku has a section where it shows the logs of the running program, there you can check if the bot received the message or had issues to connect to your server, but other people had setup the bot using the heroku deployment with a gmail account so my guess is that your email server requires some custom configuration and then automatic configuration fails in the bot, or otherwise issues to connect to your server from heroku, the logs in heroku should clarify what is going on.

btw, notice that Heroku will stop providing service for free soon, so it is not worthy, better to setup on your own hardware or VPS

1 Like

I’m stuck on the last command of step 2. Fails with error:

'ERROR: Can not perform a '--user' install. User site-packages are not visible in this virtualenv.'

Running gentoo loonix. Any troubleshooting suggestions?

UPDATE: I figured it out. Changed the setting in this file: .venvs/user_domain.tld/pyvenv.cfg

to read: -include-system-site-packages = true

OK, it’s failing now with this error:

$ simplebot --stdlog debug init $ADDR "$PASSWORD"
2023-11-27 13:57:56,965 - simplebot - DEBUG - registering plugin 'commands'
2023-11-27 13:57:56,965 - simplebot - DEBUG - registering plugin 'filters'
2023-11-27 13:57:56,982 - simplebot - DEBUG - registering plugin 'db'
2023-11-27 13:57:56,982 - simplebot - DEBUG - registered new command '/sub'
2023-11-27 13:57:56,982 - simplebot - DEBUG - registered new command '/unsub'
2023-11-27 13:57:56,983 - simplebot - DEBUG - registered new command '/help'
2023-11-27 13:57:56,983 - simplebot - DEBUG - registered new command '/unban'
2023-11-27 13:57:56,983 - simplebot - DEBUG - registered new command '/ban'
2023-11-27 13:57:56,983 - simplebot - DEBUG - registered new command '/set'
2023-11-27 13:57:56,983 - simplebot - DEBUG - registered new command '/echo'
2023-11-27 13:57:56,983 - simplebot - DEBUG - registered new filter 'simplebot_echo.echo_filter'
2023-11-27 13:58:58,034 - simplebot - INFO - Successfully configured bot@domain.tld
Traceback (most recent call last):
  File "/home/user/.local/bin/simplebot", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/user/.local/lib/python3.11/site-packages/simplebot/main.py", line 24, in main
    parser.main_run(bot=bot, args=args)
  File "/home/user/.local/lib/python3.11/site-packages/simplebot/parser.py", line 111, in main_run
    res = args.subcommand_instance.run(**kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.local/lib/python3.11/site-packages/simplebot/builtin/cmdline.py", line 152, in run
    success = bot.perform_configure_address(
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.local/lib/python3.11/site-packages/simplebot/bot.py", line 383, in perform_configure_address
    with self.account.temp_plugin(tracker) as configtracker:
  File "/usr/lib/python3.11/contextlib.py", line 144, in __exit__
    next(self.gen)
  File "/home/user/.local/lib/python3.11/site-packages/deltachat/account.py", line 671, in temp_plugin
    self._pm.unregister(plugin)
  File "/usr/lib/python3.11/site-packages/pluggy/_manager.py", line 206, in unregister
    assert name is not None, "plugin is not registered"
           ^^^^^^^^^^^^^^^^
AssertionError: plugin is not registered

hello @Seth sorry the late reply, I fixed the issue, read more about how to update your simplebot to include the fix here:

I just setup a fresh environment with the latest version of simplebot and it’s working now. Successfully tested the simplebot-echo plugin, thank you.