Cppgram  1.0.0
Easy and modern C++14 Telegram Bot API wrapper
chat.hpp
1 #ifndef CPPGRAM_CHAT_HPP
2 #define CPPGRAM_CHAT_HPP
3 
4 #include <experimental/optional>
5 #include <string>
6 
7 #include <json/json.h>
8 
9 #include "enums.hpp"
10 
11 namespace cppgram
12 {
13 namespace types
14 {
21 class Chat
22 {
25  public:
27  int_fast64_t id;
28 
31 
33  std::experimental::optional<std::string> title,
34 
37  username,
39  first_name,
41  last_name;
42 
43  Chat( Json::Value &json_chat )
44  : id( json_chat["id"].asInt64() )
45  {
46  if ( !json_chat["title"].isNull() )
47  {
48  title.emplace( json_chat["title"].asString() );
49  }
50 
51  if ( !json_chat["username"].isNull() )
52  {
53  username.emplace( json_chat["username"].asString() );
54  }
55 
56  if ( !json_chat["first_name"].isNull() )
57  {
58  first_name.emplace( json_chat["first_name"].asString() );
59  }
60 
61  if ( !json_chat["last_name"].isNull() )
62  {
63  last_name.emplace( json_chat["last_name"].asString() );
64  }
65 
66  if ( !json_chat["type"].isNull() )
67  {
68  std::vector<std::string> type_strings = {"private", "group", "supergroup", "channel"};
69  int i = 3; // type_strings.size() - 1
70  std::string chat_type = json_chat["type"].asString();
71  while ( i > 0 && chat_type.compare( type_strings[i] ) != 0 )
72  {
73  i--;
74  }
75 
76  type = static_cast<EChat>( i );
77  }
78  else
79  {
80  type = EChat::Private;
81  }
82  }
83 
84  Chat() {}
85 };
86 }
87 }
88 
89 #endif
EChat type
Type of chat.
Definition: chat.hpp:30
int_fast64_t id
Unique identifier for this chat.
Definition: chat.hpp:27
EChat
Type of the chat.
Definition: enums.hpp:11
std::experimental::optional< std::string > title
Optional. Title, for supergroups, channels and group chats
Definition: chat.hpp:33
std::experimental::optional< std::string > first_name
Optional. First name of the other party in a private chat
Definition: chat.hpp:33
std::experimental::optional< std::string > username
Optional. Username, for private chats, supergroups and channels if available
Definition: chat.hpp:33
main namespace for Cppgram
std::experimental::optional< std::string > last_name
Optional. Last name of the other party in a private chat
Definition: chat.hpp:33
Definition: enums.hpp:14
Chat object.
Definition: chat.hpp:21