python wechaty getting started
1.0.0
开箱即用的 Python Wechaty Starter 项目模板
Wechaty是一款针对微信个人账户的RPA SDK,可以帮助您用9行Python创建一个聊天机器人。
这是来自我们的 Python 微信创建者 @wj-Mcat 的精彩实时编码视频教程:https://wechaty.js.org/2020/10/26/python-wechaty-live-coding/
克隆 python-wechaty-getting-started 存储库
git clone https://github.com/wechaty/python-wechaty-getting-started
cd python-wechaty-getting-started
安装依赖项
make install
# or
pip install -r requirements.txt
为您的机器人设置令牌
您首先需要一个Wechaty Puppet服务令牌,您可以从我们的官方文档https://wechaty.js.org/docs/puppet-services/了解如何获取它。
```sh
# examples/ding-dong-bot.py : func-> main()
# it must be donut token
export WECHATY_PUPPET=wechaty-puppet-service
export WECHATY_PUPPET_SERVICE_TOKEN=your_token_at_here
```
or you can use `TOKEN` or `token` environment variable alias name to set **token**, for example:
```shell
export TOKEN=your_token_at_here
# or
export token=your_token_at_here
```
通过阅读我们的博客文章了解有关代币相关概念的更多信息:微信傀儡服务简介(提供商),@huan,2021 年 1 月 14 日
运行机器人
make bot
# or
python examples/ding-dong-bot.py
from wechaty import Wechaty
import asyncio
async def main ():
bot = Wechaty ()
bot . on ( 'scan' , lambda status , qrcode , data : print ( 'Scan QR Code to login: {} n https://wechaty.wechaty.js/qrcode/{}' . format ( status , qrcode )))
bot . on ( 'login' , lambda user : print ( 'User {} logged in' . format ( user )))
bot . on ( 'message' , lambda message : print ( 'Message: {}' . format ( message )))
await bot . start ()
asyncio . run ( main ())
[ ![ Wechaty in Python ] ( https://img.shields.io/badge/Wechaty-Python-blue )] ( https://github.com/wechaty/python-wechaty )
@wechaty/python