Skip to main content

teloxide/dispatching/dialogue/
key.rs

1use serde::{Deserialize, Serialize};
2use teloxide_core::types::{BusinessConnectionId, ChatId};
3
4/// Identifies a dialogue in an ordinary chat or in a particular business
5/// connection.
6#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
7pub struct DialogueKey {
8    pub chat_id: ChatId,
9    pub business_connection_id: Option<BusinessConnectionId>,
10}
11
12impl From<ChatId> for DialogueKey {
13    fn from(chat_id: ChatId) -> Self {
14        Self { chat_id, business_connection_id: None }
15    }
16}
17
18impl DialogueKey {
19    /// Identifies a dialogue within a business connection.
20    #[must_use]
21    pub fn business(chat_id: ChatId, business_connection_id: BusinessConnectionId) -> Self {
22        Self { chat_id, business_connection_id: Some(business_connection_id) }
23    }
24}