Telegram入門

基本常識

詞彙

telegram最主要的對象就是消息,目前爲止有不止35種類型的消息內容,主要有:

  • 文本消息( messageText)
  • 圖片消息(messagePhoto)
  • 截圖(messageScreenshotTaken )

6種不同的成員狀態:

  • chatMemberStatusAdministrator
  • chatMemberStatusBanned,
  • chatMemberStatusCreator,
  • chatMemberStatusLeft,
  • chatMemberStatusMember
  • chatMemberStatusRestricted.

四種不同的聊天形式:

  • private chats
  • basic groups
  • supergroups
  • secret chats

聊天消息去向

  • The correct order of chats in the chat list is maintained by TDLib, so the Application only needs to listen to updates that change the chat.order field and sort all chats by the pair (chat.order, chat.id) in a given chat.list.
  • TDLib通過updates嚮應用傳遞數據

用戶認證

當用戶需要認證時,TDLib嚮應用程序發送一個 updateAuthorizationState 爲了描述目前的認證狀態AuthorizationState
應用收到的第一種驗證類型是authorizationStateWaitTdlibParameters,應用通過setTdlibParameters方法來給TDLib提供初始化參數。參數主要有:

  • api_id
  • api_hash
  • database_directory
  • use_message_database
  • use_secret_chats
  • system_language_code
  • device_model
  • system_version

如果驗證成功,應用會收到新的updateAuthorizationState;如果失敗,收到的updateAuthorizationState不會更新。
應用收到的第二種認證狀態是authorizationStateWaitEncryptionKey。當收到此狀態信息時,應用必須通過checkDatabaseEncryptionKey提供數據庫加密祕鑰。
完成這些認證之後,應用將會收到authorizationStateReady,意味着認證成功並可以進行request操作。

updates

updates列表和被處理的方法

  • updateAuthorizationState
  • updateNewChat:當有新的chat時,會收到此update。當應用收到chat_id時,就不需要用getChat請求去獲得chat對象,會有一個緩存接收chat對象
  • updateUser:
  • updateBasicGroup
  • updateSupergroup
  • updateSecretChat
  • updateNewMessage
  • updateMessageSendSucceeded
  • updateMessageContent
  • updateFile

得到聊天信息

應用可以通過getChatHistory 方法得到一個chat中的信息。信息會以逆時間順序返回(也就是message_id的降序)。應用傳遞from_message_id=0會得到最後一個消息。如果應用需要更多的消息,需要調整from_message_id參數並且不斷請求。

參考

https://core.telegram.org/tdlib/getting-started

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章