From 450ff411ece6692836994a063c2c107d6eeaa7c6 Mon Sep 17 00:00:00 2001 From: link2xt Date: Sat, 18 May 2024 00:16:10 +0000 Subject: [PATCH] api(deltachat-rpc-client): add Chat.send_contact() --- deltachat-rpc-client/src/deltachat_rpc_client/chat.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/deltachat-rpc-client/src/deltachat_rpc_client/chat.py b/deltachat-rpc-client/src/deltachat_rpc_client/chat.py index e547c17a4..e7af8b9c4 100644 --- a/deltachat-rpc-client/src/deltachat_rpc_client/chat.py +++ b/deltachat-rpc-client/src/deltachat_rpc_client/chat.py @@ -2,6 +2,7 @@ from __future__ import annotations import calendar from dataclasses import dataclass +from tempfile import NamedTemporaryFile from typing import TYPE_CHECKING, Optional, Union from ._utils import AttrDict @@ -265,3 +266,11 @@ class Chat: location["message"] = Message(self.account, location.msg_id) locations.append(location) return locations + + def send_contact(self, contact: Contact): + """Send contact to the chat.""" + vcard = contact.make_vcard() + with NamedTemporaryFile(suffix=".vcard") as f: + f.write(vcard.encode()) + f.flush() + self._rpc.send_msg(self.account.id, self.id, {"viewtype": ViewType.VCARD, "file": f.name})