zoe_app_primitives/extra/rpc/
whatsappbot.rs

1use serde::{Deserialize, Serialize};
2use zoe_wire_protocol::version::Version;
3
4pub static CURRENT_WA_BOT_PROTOCOL_VERSION: &str = "0.1.0-dev.0";
5pub static CURRENT_WA_BOT_PROTOCOL_VERSION_REQ: &str = ">=0.1.0-dev.0";
6
7/// WhatsApp bot service for remote procedure calls
8#[tarpc::service]
9pub trait WhatsAppBot {
10    /// Check if the whatsapp bot is responding
11    async fn ping() -> String;
12}
13
14#[derive(Debug, Clone, Serialize, Deserialize)]
15pub enum WhatsAppBotError {
16    /// You need to upgrade your client to at least the version provided
17    PleaseUpgrade(Version),
18    /// There was some error within the communication to the bot,
19    /// please create a new session
20    ReEstablishSession,
21    /// I can't let you do that, dave.
22    RequiresAuthentication,
23    /// The bot error in general, check the string for more details
24    BotError(String),
25}
26
27/// Message expected when trying to connect to a whatsapp bot
28#[derive(Debug, Clone, Serialize, Deserialize)]
29pub struct WhatsAppBotSessionInit {
30    /// the protocol versions the client supports
31    pub versions: Vec<Version>,
32}
33
34/// Why the session init failed
35#[derive(Debug, Clone, Serialize, Deserialize)]
36pub enum WhatsAppBotSessionInitFailure {
37    /// The bot error in general, check the string for more details
38    BotError(String),
39    /// The client has no compatible version with the bot, the vector is the
40    /// list of supported versions by the bot
41    NoCompatibleVersion(Vec<Version>),
42}
43
44/// What is being responded by the whatsapp bot when trying to
45/// establish a session
46#[derive(Debug, Clone, Serialize, Deserialize)]
47pub enum WhatsAppBotSessionInitResponse {
48    /// The version the bot agreed to use from the list of supported versions
49    /// sent by the client
50    Success(Version),
51    Failure(WhatsAppBotSessionInitFailure),
52}