Hi all,
I’m playing around with the DeltaChat python bindings (GitHub - deltachat/deltachat-core-rust: Delta Chat Rust Core library, used by Android/iOS/desktop apps and bindings ) and could run the echo_and_quit.py successfully. All of the bot examples assume, that one account send them a message which they can reply.
Now my question:
Is it possible to send a message to a regular DeltaChat contact (e.g. for IoT devices reporting certain state information)?
Thanks for some clarification,
Matthias
Simon
June 27, 2021, 6:06pm
2
yes it’s possible to send messages with the python bindings, without the need for it being a reply to a user sent message.
Though I currently don’t have an example for this usage ready.
You might look at the code for run_cmdline
copy its code, remove what you don’t need and use Account
directly as you please.
def unregister_global_plugin(plugin):
gm = hookspec.Global._get_plugin_manager()
gm.unregister(plugin)
register_global_plugin(events)
def run_cmdline(argv=None, account_plugins=None):
""" Run a simple default command line app, registering the specified
account plugins. """
import argparse
if argv is None:
argv = sys.argv
parser = argparse.ArgumentParser(prog=argv[0] if argv else None)
parser.add_argument("db", action="store", help="database file")
parser.add_argument("--show-ffi", action="store_true", help="show low level ffi events")
parser.add_argument("--email", action="store", help="email address")
You can create a contact (admin@example.com
in this case) and then open 1:1 chat with them like this:
contact = account.create_contact("admin@example.com", name="Someone")
chat = contact.create_chat()
msg = chat.send_text("Report device metrics here")
There are many examples in the tests:
from __future__ import print_function
import pytest
import os
import sys
import queue
import time
from deltachat import const, Account
from deltachat.message import Message
from deltachat.tracker import ImexTracker
from deltachat.hookspec import account_hookimpl
from deltachat.capi import ffi, lib
from deltachat.cutil import iter_array
from datetime import datetime, timedelta
@pytest.mark.parametrize("msgtext,res", [
("Member Me (tmp1@x.org) removed by tmp2@x.org.",
("removed", "tmp1@x.org", "tmp2@x.org")),
("Member With space (tmp1@x.org) removed by tmp2@x.org.",
("removed", "tmp1@x.org", "tmp2@x.org")),
This file has been truncated. show original
Hi @Simon @link2xt ,
thanks for your help! Will try it within the next days.
Cheers
Matthias