# Teletap - Telegram wrapper library for telegram-cli
An easy to use Python wrapper library for Telegram (telegram-cli v1.1.1) daemon over network sockets
----
## Prerequisites
It is assumed that you already have `telegram-cli` up and running and that you able to login.
If you haven't, visit https://github.com/vysheng/tg, run the program and sign-in with your existing account or register for a new one.
## Installation
$ git clone https://github.com/rohit-h/teletap && cd teletap && python setup.py install
## Usage
There are five basic elements/object references you will need to pay attention to in this design:
1. **Client**: Teletap object used to initialize the telegram-cli daemon, listen for unread messages and attaching message response handlers.
2. **User**: Class-type that contains user information. Currently accessible instance fields are : user_id, user_name, user_phone, user_handle, user_last_seen
3. **Group**: Class-type to store group ID for now. More methods to be added as we find more useful things to do with it.
4. **Action**: Client interactions within a message handler are done through the Action instance. Currently supported methods are : `send_message(User, message)` ,`send_typing(User)` ,`send_image(User, file)` and `send_text(User, file)` with more to be added in the near future.
5. **Handlers**: These are user-defined methods that can be used to process incoming messages. The method signature is
def message_handler(action, user, message, group=None):
# This function can be attached to both user/group responders in the client
# since it contains the group argument. The function needs to take care of
# knowing where the message is coming from depending on group == None being
# True or False
----
## Examples
### Loopback test
The following code waits for users to send messages. Upon receiving them, the program will send the same text message back to the sender. In case of group messages, the message is sent to the original sender and to the group
#!/usr/bin/python2
from teletap import libteletap
import time
def user_responder(action, user, message):
print ' >>> Incoming message from {0} : {1}'.format(user.user_name, message)
print ' <<< Outgoing message for {0} : {1}'.format(user.user_name, message)
action.send_typing(user); time.sleep(2)
action.send_message(user, message)
def group_responder(action, group, user, message):
print ' >>> Incoming message from {0} on {1} : {2}'.format(user.user_name, group.group_id, message)
action.send_message(user, message) # Send to user
#action.send_message(group, message) # Send to group [Use responsibly!]
if __name__ == '__main__':
CLIENT = Teletap(binary='/usr/bin/telegram-cli', keyfile='/etc/telegram-cli/tg-server.pub', logs='/var/log/telegram.log', quiet=False)
CLIENT.attach_user_responder(user_responder) # Attach message handler for user chats
CLIENT.attach_group_responder(group_responder) # Attach message handler for group chats
try:
CLIENT.begin() # Connect & start main event loop
except KeyboardInterrupt:
CLIENT.shutdown() # Gracefully terminate client and daemon
Check the examples folder for more..
没有合适的资源?快使用搜索试试~ 我知道了~
teletap:通过网络套接字为 Telegram (telegram-cli) 守护进程使用 Python 包装库-源码
共8个文件
py:5个
gitignore:1个
md:1个
需积分: 9 0 下载量 67 浏览量
2021-06-20
13:42:45
上传
评论
收藏 14KB ZIP 举报
温馨提示
Teletap - 电报 cli 的电报包装库 一个易于使用的 Python 包装库,用于通过网络套接字的 Telegram (telegram-cli v1.1.1) 守护进程 先决条件 假设您已经启动并运行了telegram-cli ,并且您可以登录。 如果还没有,请访问 ,运行该程序并使用您现有的帐户登录或注册一个新帐户。 安装 $ git clone https://github.com/rohit-h/teletap && cd teletap && python setup.py install 用法 在此设计中,您需要注意五个基本元素/对象引用: Client : Teletap 对象,用于初始化 Telegram-cli 守护进程,侦听未读消息并附加消息响应处理程序。 User :包含用户信息的类类型。 当前可访问的实例字段有:user_id、user_name、us
资源详情
资源评论
资源推荐
收起资源包目录
teletap-master.zip (8个子文件)
teletap-master
.gitignore 13B
README.md 3KB
examples
clevertelbot.py 1KB
loopback.py 1KB
LICENSE 18KB
teletap
__init__.py 0B
libteletap.py 9KB
setup.py 295B
共 8 条
- 1
温暖如故
- 粉丝: 24
- 资源: 4642
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- chromedriver-win64-121版本所有资源打包下载
- C语言《基于STC8A8K64D4的AD电压表及温度计的设计与实现》+项目源码+文档说明
- java项目,课程设计-#-ssm-mysql-在线物业管理系统.zip
- 技术资料分享任天堂产品系统文件很好的技术资料.zip
- chromedriver-win64-120版本所有资源打包下载
- 1dewdwedewdwdwed
- BEV模型部署全栈教程(3D检测+车道线+Occ)
- chromedriver-win64-119版本所有资源打包下载
- 技术资料分享嵌入式实时操作系统μCOS-II原理及应用-任哲(高清版本)很好的技术资料.zip
- chromedriver-win64-118版本所有资源打包下载
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0