『技术流』Telegram Bot接管WeChat信息
本文来自用户 @Jack Chen 的投稿!
写在前面
最近自学Python接触的Telegram Bot编程,重新将之前一年多以前没搞懂的ehForwarderBot(简称:EFB)拿出来研究,自从学会富强接触上Telegram后无法自拔,作为一个及时通信平台,它可能不是最安全的,但绝对是在我所使用过的IM里面用户体验最棒的,Emmm,QQ,WeChat就不多说了,除了及时通讯外,增加的功能都是那啥。。。。。。但不能摆脱,一直想有一个平台将QQ,微信消息集中起来,装那么多APP烦,而EFB实现了这个功能之一。
目前网上基本的教程是基于EFB2.0以前的,反正我谷歌出来的几页都是一年前的,由于EFB2.0后安装方式大幅度简化了,原有的安装方式也大不相同。
由于使用的网页版微信,所以仅支持微信网页版所支持的功能以及消息类型,下面我们来看看效果图:
前期准备
- 一台海外VPS,为毛,Telegram都被墙了,无法访问Telegram你怎么玩
 - Ubuntu 16.04 我常用的Linux Server系统
 - 一个你自己的Telegram Bot
 
获取Telegram相关信息
- 创建Telegram Bot
- 首先找到BotFather,这是它的链接BotFather
 - 然后向BotFather发送指令
/newbot,返回信息后输入Bot名字 - 接下来继续向BotFather发送Bot的用户名,切记: 取名规则最后面必须包含
bot/Bot - 完成后会提供一个API,这个后面需要用到
 
 
- 个性化设置Bot
- 设置头像向BotFather发送
/setuserpic,选择刚刚创建的Bot,然后向BotFather发送一张图片就行了 - 设置介绍(Description),打开来聊天窗口看到的信息向BotFather发送
/setdescription,选择刚刚创建的Bot,然后向BotFather发送Description - 设置介绍(About),用户在打开你Bot连接看到的介绍向BotFather发送
/setabouttext,选择刚刚创建的Bot,然后向BotFather发送Description 
 - 设置头像向BotFather发送
 
- 获取Telegram账号ID打开这个连接并添加:get_id_bot,点击
start,会返回格式如下的信息Hello ***** Your Chat ID = ***** User Name = *****
其中Chat ID就是我们需要的
 
部署ehForwarderBot
- 安装Python3
有些服务商提供的Ubuntu16.04同时安装了Python 2/3俩个版本,emmm,不用理会,直接跟我走
sudo add-apt-repository ppa:jonathonf/python-3.6 sudo apt-get update sudo apt-get install python3.6
切换Python3.*版本
update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.5 1 update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 2 update-alternatives --config python3
在切换Python版本后安装EFB可能会报这个错误
No module named "apt_pkg",如果没报跳过这步,但建议执行下cd /usr/lib/python3/dist-packages/ sudo cp apt_pkg.cpython-35m-x86_64-linux-gnu.so apt_pkg.cpython-36m-x86_64-linux-gnu.so
 - 安装EFB全套工具需要的依赖
sudo apt-get install python3.6-gdbm python3-pip sudo apt-get install libtiff5-dev libjpeg8-dev zlib1g-dev libfreetype6-dev liblcms2-dev libwebp-dev tcl8.5-dev tk8.5-dev sudo apt-get install git libmagic-dev ffmpeg gcc make autoconf automake libtool python-setuptools python-pip git screen pip3 install pillow
编译安装libwebp
git clone https://github.com/webmproject/libwebp.git ./configure make make install
 - 安装EFB-ETM-EWS
pip3 install ehforwarderbot pip3 install efb-telegram-master pip3 install efb-wechat-slave
 
配置ehForwarderBot接入WeChat的相关信息
- 创建配置信息存放目录
mkdir -p ~/.ehforwarderbot/profiles/default mkdir -p ~/.ehforwarderbot/profiles/default/blueset.telegram
 - 写入配置信息
vim ~/.ehforwarderbot/profiles/default/config.yaml
token: "12345678:1a2b3c4d5e6g7h8i9j" admins: - 102938475 master_channel: "blueset.telegram" slave_channels: - "blueset.wechat"
配置信息说明:
- token:这个是你创建的Telegram Bot的API
 - admins:这个是你Telegram账号ID
 
vim ~/.ehforwarderbot/profiles/default/blueset.telegram/config.yaml
token: "12345678:1a2b3c4d5e6g7h8i9j" admins: - 102938475 # API tokens required for speech recognition speech_api: # Microsoft (Bing) speech recognition token # API key can be obtained from # https://azure.microsoft.com/en-us/try/cognitive-services/ bing: "VOICE_RECOGNITION_TOKEN" # Baidu speech recognition token # API key can be obtained from # http://yuyin.baidu.com/ baidu: app_id: 123456 api_key: "API_KEY_GOES_HERE" secret_key: "SECRET_KEY_GOES_HERE" flags: option_one: 10 option_two: false option_three: "foobar"配置信息说明:
- token,admins同理
 - speech_api:这个是语音功能,按需是否开启,不开启把
speech_api删除 
 
启动ehForwardBot
EFB提供俩种方式启动:
ehforwarderbot
python3 -m ehforwarderbot
然后打开你的Bot输入/start,就能开始接收消息了,BTW,微信的所有消息包括群组公众号信息都会发到这个Bot上,这必然会出现杂乱(如果你微信很活跃的话),怎么解决这个办法看官方文档:efb-telegram-master,由于我的微信不怎么活跃这个解决办法你们自己去搞定吧。
参考文档
版权声明:
作者:我是小马甲~                                    
链接:https://fandai.gezi.workers.dev/8054.html
来源:如有乐享                                    
文章版权归作者所有,未经允许请勿转载。
                


clay
逗比端
岩兔站
华山小穷奇大王