I’m looking at the Rust API for bots and I cannot find the proper way to create a new Chat for a given mail address. It appears that the only way to access such 1:1 chats is by having them already in the database, which would imply that the bot cannot start a conversation with any contact it wants (ie: it’s the contact who must send the first message, as in Telegram API).
Is that by design? Is it a lack of feature? Or is it simply that I’m not able to figure it out?
The function you are looking for is Contact::add_or_lookup, though I personally would also have expected some more clear naming like a method with “create” or “new” in it’s name.
Thx for the fast reply . However, I’m not sure if that’s what I’m looking for…
That function adds a contact, but I still need a Chat to use send_msg, and that’s the root of my problem: how do I create a Chat if it is not already present in the DB.
Maybe creating a group chat with create_group_chat and adding a single contact would work? I don’t think so, because it would still allow me to add more contacts and the Chat object would not return Single as chat type, I guess…
I’ll review the C API docs in more depth because I hadn’t the link (thx for that).
Regarding Rust docs, I didn’t know about the link but I generated them with cargo doc locally .
hi @Ivan, I guess you can use ChatId::create_for_contact
I am not a Rust developer, but if I would create a bot in Rust I would have a look at the usage of the API by the deltachat-jsonrpc program, for example, this is how the Rust API is used to create a 1:1 chat there:
I was misled by the fact that ChatId sounded like an “empty” type just to wrap the number that identified the chat so I didn’t really realise that I could find the method there.
In fact, looking at the ContactId API for example, there are no methods to create contacts because they are in Contact, as @Simon pointed out in the first answer. Thus, I expected something like Chat::create_for_contact or Contact::create_chat…
In any case, thx to both for the answers, I was getting crazy