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

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