Skip to main content

teloxide_ng/dispatching/dialogue/
get_chat_id.rs

1use crate::types::{
2    CallbackQuery, Chat, ChatId, ChatJoinRequest, ChatMemberUpdated, Message, Update,
3};
4
5/// Something that may have a chat ID.
6pub trait GetChatId {
7    #[must_use]
8    fn chat_id(&self) -> Option<ChatId>;
9}
10
11impl GetChatId for Message {
12    fn chat_id(&self) -> Option<ChatId> {
13        Some(self.chat.id)
14    }
15}
16
17impl GetChatId for CallbackQuery {
18    fn chat_id(&self) -> Option<ChatId> {
19        self.message.as_ref().map(|mes| mes.chat().id)
20    }
21}
22
23impl GetChatId for Update {
24    fn chat_id(&self) -> Option<ChatId> {
25        self.chat().map(|chat| chat.id)
26    }
27}
28
29impl GetChatId for Chat {
30    fn chat_id(&self) -> Option<ChatId> {
31        Some(self.id)
32    }
33}
34
35impl GetChatId for ChatMemberUpdated {
36    fn chat_id(&self) -> Option<ChatId> {
37        Some(self.chat.id)
38    }
39}
40
41impl GetChatId for ChatJoinRequest {
42    fn chat_id(&self) -> Option<ChatId> {
43        Some(self.chat.id)
44    }
45}