use std::path::Path; use jsonrpc_client_transports::{transports::ipc, RpcError}; use jsonrpc_core::serde::Deserialize; use jsonrpc_derive::rpc; use tokio::net::ToSocketAddrs; pub type SignalCliClient = gen_client::Client; #[rpc(client, params = "named")] pub trait Rpc { #[rpc(name = "addDevice", params = "named")] fn add_device(&self, account: Option, uri: String) -> Result; #[rpc(name = "block", params = "named")] fn block( &self, account: Option, recipients: Vec, #[allow(non_snake_case)] groupIds: Vec, ) -> Result; #[rpc(name = "getUserStatus", params = "named")] fn get_user_status(&self, account: Option, recipients: Vec) -> Result; #[rpc(name = "joinGroup", params = "named")] fn join_group(&self, account: Option, uri: String) -> Result; #[rpc(name = "finishLink", params = "named")] fn finish_link( &self, #[allow(non_snake_case)] deviceLinkUri: String, #[allow(non_snake_case)] deviceName: String, ) -> Result; #[rpc(name = "listAccounts", params = "named")] fn list_accounts(&self) -> Result; #[rpc(name = "listContacts", params = "named")] fn list_contacts(&self, account: Option) -> Result; #[rpc(name = "listDevices", params = "named")] fn list_devices(&self, account: Option) -> Result; #[rpc(name = "listGroups", params = "named")] fn list_groups(&self, account: Option) -> Result; #[rpc(name = "listIdentities", params = "named")] fn list_identities(&self, account: Option, number: Option) -> Result; #[rpc(name = "listStickerPacks", params = "named")] fn list_sticker_packs(&self, account: Option) -> Result; #[rpc(name = "quitGroup", params = "named")] fn quit_group( &self, account: Option, #[allow(non_snake_case)] groupId: String, delete: bool, admins: Vec, ) -> Result; #[rpc(name = "register", params = "named")] fn register( &self, account: Option, voice: bool, captcha: Option, ) -> Result; #[rpc(name = "removeContact", params = "named")] fn remove_contact( &self, account: Option, recipient: String, forget: bool, ) -> Result; #[rpc(name = "removeDevice", params = "named")] fn remove_device( &self, account: Option, #[allow(non_snake_case)] deviceId: u32, ) -> Result; #[rpc(name = "removePin", params = "named")] fn remove_pin(&self, account: Option) -> Result; #[rpc(name = "remoteDelete", params = "named")] fn remote_delete( &self, account: Option, #[allow(non_snake_case)] targetTimestamp: u64, recipients: Vec, #[allow(non_snake_case)] groupIds: Vec, #[allow(non_snake_case)] noteToSelf: bool, ) -> Result; #[rpc(name = "send", params = "named")] fn send( &self, account: Option, recipients: Vec, #[allow(non_snake_case)] groupIds: Vec, #[allow(non_snake_case)] noteToSelf: bool, #[allow(non_snake_case)] endSession: bool, message: String, attachments: Vec, mentions: Vec, #[allow(non_snake_case)] quoteTimestamp: Option, #[allow(non_snake_case)] quoteAuthor: Option, #[allow(non_snake_case)] quoteMessage: Option, #[allow(non_snake_case)] quoteMention: Vec, sticker: Option, ) -> Result; #[rpc(name = "sendContacts", params = "named")] fn send_contacts(&self, account: Option) -> Result; #[rpc(name = "sendReaction", params = "named")] fn send_reaction( &self, account: Option, recipients: Vec, #[allow(non_snake_case)] groupIds: Vec, #[allow(non_snake_case)] noteToSelf: bool, emoji: String, #[allow(non_snake_case)] targetAuthor: String, #[allow(non_snake_case)] targetTimestamp: u64, remove: bool, ) -> Result; #[rpc(name = "sendReceipt", params = "named")] fn send_receipt( &self, account: Option, recipient: String, #[allow(non_snake_case)] targetTimestamps: Vec, r#type: String, ) -> Result; #[rpc(name = "sendSyncRequest", params = "named")] fn send_sync_request(&self, account: Option) -> Result; #[rpc(name = "sendTyping", params = "named")] fn send_typing( &self, account: Option, recipients: Vec, #[allow(non_snake_case)] groupIds: Vec, stop: bool, ) -> Result; #[rpc(name = "setPin", params = "named")] fn set_pin(&self, account: Option, pin: String) -> Result; #[rpc(name = "submitRateLimitChallenge", params = "named")] fn submit_rate_limit_challenge( &self, account: Option, challenge: String, captcha: String, ) -> Result; #[rpc(name = "startLink", params = "named")] fn start_link(&self, account: Option) -> Result; #[rpc(name = "trust", params = "named")] fn trust( &self, account: Option, recipient: String, #[allow(non_snake_case)] trustAllKnownKeys: bool, #[allow(non_snake_case)] verifiedSafetyNumber: Option, ) -> Result; #[rpc(name = "unblock", params = "named")] fn unblock( &self, account: Option, recipients: Vec, #[allow(non_snake_case)] groupIds: Vec, ) -> Result; #[rpc(name = "unregister", params = "named")] fn unregister( &self, account: Option, #[allow(non_snake_case)] deleteAccount: bool, ) -> Result; #[rpc(name = "updateAccount", params = "named")] fn update_account( &self, account: Option, #[allow(non_snake_case)] deviceName: Option, ) -> Result; #[rpc(name = "updateConfiguration", params = "named")] fn update_configuration( &self, account: Option, #[allow(non_snake_case)] readReceiptes: Option, #[allow(non_snake_case)] unidentifiedDeliveryIndicators: Option, #[allow(non_snake_case)] typingIndicators: Option, #[allow(non_snake_case)] linkPreviews: Option, ) -> Result; #[rpc(name = "updateContact", params = "named")] fn update_contact( &self, account: Option, recipient: String, name: Option, expiration: Option, ) -> Result; #[rpc(name = "updateGroup", params = "named")] fn update_group( &self, account: Option, #[allow(non_snake_case)] groupId: Option, name: Option, description: Option, avatar: Option, member: Vec, #[allow(non_snake_case)] removeMember: Vec, admin: Vec, #[allow(non_snake_case)] removeAdmin: Vec, ban: Vec, unban: Vec, #[allow(non_snake_case)] resetLink: bool, #[allow(non_snake_case)] link: Option, #[allow(non_snake_case)] setPermissionAddMember: Option, #[allow(non_snake_case)] setPermissionEditDetails: Option, #[allow(non_snake_case)] setPermissionSendMessages: Option, expiration: Option, ) -> Result; #[rpc(name = "updateProfile", params = "named")] fn update_profile( &self, account: Option, #[allow(non_snake_case)] givenName: Option, #[allow(non_snake_case)] familyName: Option, about: Option, #[allow(non_snake_case)] aboutEmoji: Option, avatar: Option, #[allow(non_snake_case)] removeAvatar: bool, ) -> Result; #[rpc(name = "uploadStickerPack", params = "named")] fn upload_sticker_pack(&self, account: Option, path: String) -> Result; #[rpc(name = "verify", params = "named")] fn verify( &self, account: Option, #[allow(non_snake_case)] verificationCode: String, pin: Option, ) -> Result; #[pubsub( subscription = "receive", subscribe, name = "subscribeReceive", params = "named" )] fn subscribe_receive(&self, _: Self::Metadata, _: Subscriber, account: Option); #[pubsub(subscription = "receive", unsubscribe, name = "unsubscribeReceive")] fn unsubscribe_receive(&self, _: Option, _: SubscriptionId) -> Result; #[rpc(name = "version")] fn version(&self) -> Result; } #[derive(Deserialize)] #[serde(rename_all = "camelCase")] pub struct JsonLink { pub device_link_uri: String, } pub async fn connect_tcp(tcp: impl ToSocketAddrs) -> Result { super::tcp::connect::<_, SignalCliClient>(tcp).await } pub async fn connect_unix(socket_path: impl AsRef) -> Result { ipc::connect::<_, SignalCliClient>(socket_path).await }