Skip to content

Example echobot.py is broken (ImportError: cannot import name 'MsgData' from 'deltachat2') #89

Description

@codiflow

Following the steps from this repository resulted in the following error message:

$ python ./echobot.py init DCACCOUNT:https://nine.testrun.org/new

Traceback (most recent call last):
  File "/root/deltachat-bot/./echobot.py", line 5, in <module>
    from deltachat2 import MsgData, events
ImportError: cannot import name 'MsgData' from 'deltachat2' (/root/user/.venv/lib/python3.13/site-packages/deltachat2/__init__.py)

Looking into the repository of the Python library shows that the code has to be changed:

Working version of echobot.py:

#!/usr/bin/env python3
from deltachat2 import MessageData, events
from deltabot_cli import BotCli

cli = BotCli("echobot")

@cli.on(events.RawEvent)
def log_event(bot, accid, event):
    bot.logger.info(event)

@cli.on(events.NewMessage)
def echo(bot, accid, event):
    msg = event.msg
    bot.rpc.send_msg(accid, msg.chat_id, MessageData(text=msg.text))

if __name__ == "__main__":
    cli.start()

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions