telegram-rb, 与 Telegram CLI通信的ruby 包装器

分享于 

6分钟阅读

GitHub

  繁體 雙語
A ruby client for telegram-cli, uses unix-socket and EventMachine
  • 源代码名称:telegram-rb
  • 源代码网址:http://www.github.com/ssut/telegram-rb
  • telegram-rb源代码文档
  • telegram-rb源代码下载
  • Git URL:
    git://www.github.com/ssut/telegram-rb.git
    Git Clone代码到本地:
    git clone http://www.github.com/ssut/telegram-rb
    Subversion代码到本地:
    $ svn co --depth empty http://www.github.com/ssut/telegram-rb
    Checked out revision 1.
    $ cd repo
    $ svn up trunk
    
    ruby的电子邮件 API !

    DUBGem VersionCode ClimateInline docs

    Gitter

    一个 ruby 包装器,它与电报通信。

    安装

    要求

    • 你需要先安装 telegram 版本 1.3.0或者更高版本。

    RubyGems

    为了使用电报,你需要安装 gem ( 手动或者使用 Bundler ),并需要 ruby 应用程序中的库:

    $ gem install telegram-rb

    或者在你的Gemfile 中:

    # latest stablegem 'telegram-rb', require:'telegram'# or track master repogem 'telegram-rb', github:'ssut/telegram-rb', require:'telegram'

    用法

    库使用 EventMachine,所以逻辑被封装在 EM.run 中。

    # When using Bundler, let it load all librariesrequire'bundler'Bundler.require(:default) # Otherwise, require 'telegram', which will load its dependencies# require 'telegram'EM.run do telegram =Telegram::Client.newdo |cfg, auth|
     cfg.daemon ='/path/to/tg/bin/telegram-cli' cfg.key ='/path/to/tg/tg-server.pub' cfg.config_file ='/path/to/config'# optional, default file will be used if not set cfg.profile ='user2'# optional, the profiles must be configured in ~/.telegram-cli/config cfg.logger =Logger.new(STDOUT) # optional, default logger will be created if not set# optional properties, could be used for authorization/registration telegram accounts auth.phone_number ='<valid phone number>' auth.confirmation_code =-> { '<received confirmation code via sms or call>' }
     auth.register = { # required in case with registration new telegram accountfirst_name:'<user first name>',
     last_name:'<user last name>' }
     end telegram.connect do# This block will be executed when initialized.# See your telegram profileputs telegram.profile
     telegram.contacts.each do |contact|
     puts contact
     end telegram.chats.each do |chat|
     puts chat
     end# Event listeners# When you've received a message: telegram.on[Telegram::EventType::RECEIVE_MESSAGE] =Proc.newdo |event|
     # `tgmessage` is TelegramMessage instanceputs event.tgmessage
     end 
     # When you've sent a message: telegram.on[Telegram::EventType::SEND_MESSAGE] =Proc.newdo |event|
     puts event
     end# When connection is closed: telegram.on_disconnect =Proc.newdoputs'Connection with telegram-cli is closed'endendend

    文档

    你可以从这里查看来自的文档。

    我的目标是为项目提供完全documentated代码,这样开发人员就可以轻松使用这个库 !

    实时覆盖( TODO )

    • 消息/多媒体
      • 向特定用户或者聊天发送键入信号
      • 向特定用户或者聊天发送消息
      • 向特定用户或者聊天发送图像
      • 向特定用户或者聊天发送视频
      • 标记为已读所有收到的邮件
      • 下载某人发送的图片
      • 向特定用户转发邮件
      • 设置个人头像
    • 群组聊天选项
      • 将用户添加到组
      • 从组中删除用户
      • 从群组离开
      • 创建新的群组聊天
      • 设置群组聊天照片
      • 重命名群组聊天标题
    • 搜索
      • 从会话中搜索特定的消息
      • 从所有转换中搜索特定的消息
    • 秘密聊天
      • 秘密聊天中的回复消息
      • 秘密聊天的加密密钥可视化
      • 创建新的机密聊天
    • 统计和各种信息
      • 获取用户配置文件
      • 获取聊天列表
      • 获取联系人列表
      • 获取历史并将它的标记为已读
    • 卡卡
      • 导出卡
      • 导入卡

    如果有 Bug 或者你想要改进,fork 项目,并在它自己的分支中实现你的特性或者补丁。

    许可证

    在MIT许可证下授权。

    
    The MIT License (MIT)
    
    
    
    Copyright (c) 2015 SuHun Han
    
    
    
    Permission is hereby granted, free of charge, to any person obtaining a copy
    
    
    of this software and associated documentation files (the"Software"), to deal
    
    
    in the Software without restriction, including without limitation the rights
    
    
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    
    
    copies of the Software, and to permit persons to whom the Software is
    
    
    furnished to do so, subject to the following conditions:
    
    
    
    The 上面 copyright notice and this permission notice shall be included in all
    
    
    copies or substantial portions of the Software.
    
    
    
    THE SOFTWARE IS PROVIDED"AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    
    
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    
    
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    
    
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    
    
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    
    
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    
    
    SOFTWARE.
    
    
    
    

    COM  COMM  WRAP  换行  TEL  Telegram  
    相关文章