Giter Club home page Giter Club logo

puppet-oicq's Introduction

WECHATY PUPPET OICQ (基于OICQ项目的QQ机器人)

Powered by Wechaty

NPM Version npm (tag)

运行方法

配置系统环境变量

  1. WECHATY_PUPPET_OICQ_QQ:要登录的QQ号

安装依赖

将代码clone到本地,执行npm install

运行示例代码

npm run start

按照提示完成扫码完成后按下回车,即可运行示例机器人

Getting Started with Wechaty

export WECHATY_PUPPET=wechaty-puppet-oicq
npm start

Learn more for building your first Wechaty bot at https://github.com/wechaty/wechaty-getting-started

项目介绍

“开源软件供应链点亮计划-暑期2021”(以下简称 暑期2021)是由中科院软件所与 openEuler 社区共同举办的一项面向高校学生的暑期活动,旨在鼓励在校学生积极参与开源软件的开发维护,促进国内优秀开源软件社区的蓬勃发展。

根据项目的难易程度和完成情况,参与者还可获取“开源软件供应链点亮计划-暑期2021”活动奖金和奖杯。

官网:https://summer.iscas.ac.cn

Wechaty

Wechaty 是一个开源聊天机器人框架SDK,具有高度封装、高可用的特性,支持NodeJs, Python, Go 和Java 等多语言版本。在过去的5年中,服务了数万名开发者,收获了 Github 的 9600 Star。同时配置了完整的DevOps体系并持续按照Apache 的方式管理技术社区。

项目名称

开发支持 QQ 聊天软件的 Wechaty Puppet Provider 模块

背景介绍

Wechaty 社区目前已经支持微信、Whatsapp、企业微信、飞书等常见流行即时通讯工具,并且能够通过多语言 SDK (比如 Python Wechaty) 进行调用。

QQ 是国内和微信并列的两大聊天软件。我们在本次 Summer 2021 的项目中,Wechaty 希望可以实现对 QQ Chatbot 的支持。通过 Wechaty Puppet 的接口,可以将 QQ 进行 RPA 封装,使其成为 wechaty-puppet-qq 供 Wechaty 开发者方便接入 QQ 平台,使其成为 Wechaty 可以使用的社区生态模块。

需求介绍

使用 https://github.com/wechaty/wechaty-puppet-mock 项目作为模版,参考社区其他的 Wechaty Puppet Provider 代码模块,对 QQ 进行规划、RPA选型、原型测试,和最终的代码封装。

这里有一个专门讲解如何开发 Wechaty Puppet Provider 的 workshop 视频,它以 wechaty-puppet-official-account 作为例子,做了从0到1的入门讲解:Wechaty Workshop for Puppet Makers: How to make a Puppet for Wechaty。通过观看这一个小时的视频,应该可以系统性的了解如何完成构建一个 Wechaty Puppet Provider 模块。

在初期开发中,能够实现文本消息的接收和发送,即可完成原型验证 POC 。

还可以参考以下链接:

  1. TypeScript Puppet Official Documentation: https://wechaty.github.io/wechaty-puppet/typedoc/classes/puppet.html
  2. Wechaty Puppet Specification: https://wechaty.js.org/docs/specs/puppet
  3. https://github.com/wechaty/wechaty-puppet-mock

导师联系方式

  1. 李佳芮: Wechaty co-creator, Founder & CEO of Juzi.BOT ([email protected])
  2. 李卓桓:Wechaty creator, Tencent TVP of Chatbot ([email protected])

项目产出目标

  1. 每日代码 commit
  2. 每周提交一份 report (回复本 issue)
  3. 每两周一次在线会议
  4. 发布 Git Repo wechaty-puppet-qq
  5. 可以通过 Wechaty 加载 wechaty-puppet-qq 模块,并通过 QQ RPA 底层,实现文本消息的收发功能
  6. 提供一个 examples/ding-dong-bot.ts ,完成“接收到文字消息ding时,自动回复消息dong"的功能
  7. 配置 GitHub Actions 实现自动化测试* (可选)

项目技术栈

  1. TypeScript programming language
  2. Git
  3. RPA

Links

相关链接

History

main v1.0 (Oct 29, 2021)

Release v1.0 of Wechaty Puppet Provider for QQ.

  • v0.1 (Sep 22, 2021): ES Modules support

v0.0.1 (Jun 22, 2021)

Author

@naivebird

Copyright & License

  • Code & Docs © 2021-2021 @naivebird and Wechaty Contributors
  • Code released under the Apache-2.0 License
  • Docs released under Creative Commons

puppet-oicq's People

Contributors

anaivebird avatar huan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

puppet-oicq's Issues

Rewrite README to fit the project, and make CI green.

It's great to see that we have this project created!

Please make the README fit this project as the first step, so that other developers from the Wechaty community can understand what this project is, and how to use it!

And also please make the CI green.

Disable the output message from `oicq`

[2021-10-01T09:58:34.580] [ERROR] [Android:12345] - 扫描二维码失败,请重新获取。
[2021-10-01T09:58:34.683] [MARK] [Android:12345] - 请用手机QQ扫描二维码,若打印出错请打开:/home/huan/git/wechaty/wechaty-getting-started/data/12345/qrcode.png

The above message should be disabled because all output messages should be sent out via our log (brolog) module.

If needed, we should get those messages and then use log.verbose(...) to output them, so that we can control them by WECHATY_LOG environment variable.

Working with WECHATY_PUPPET=wechaty-puppet-oicq broken

15:18:16 VERB PuppetManager resolveName(wechaty-puppet-oicq)
CustomError: Cannot find package 'wechaty-puppet-oicq' imported from /home/anelderly/wechaty-getting-started/node_modules/wechaty/dist/esm/src/puppet-manager.js
    at packageResolve (/home/anelderly/wechaty-getting-started/node_modules/ts-node/dist-raw/node-esm-resolve-implementation.js:774:9)
    at moduleResolve (/home/anelderly/wechaty-getting-started/node_modules/ts-node/dist-raw/node-esm-resolve-implementation.js:815:18)
    at Object.defaultResolve (/home/anelderly/wechaty-getting-started/node_modules/ts-node/dist-raw/node-esm-resolve-implementation.js:929:11)
    at /home/anelderly/wechaty-getting-started/node_modules/ts-node/src/esm.ts:68:38
    at Generator.next (<anonymous>)
    at /home/anelderly/wechaty-getting-started/node_modules/ts-node/dist/esm.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (/home/anelderly/wechaty-getting-started/node_modules/ts-node/dist/esm.js:4:12)
    at resolve (/home/anelderly/wechaty-getting-started/node_modules/ts-node/dist/esm.js:32:16)
    at Loader.resolve (internal/modules/esm/loader.js:86:40)
    at Loader.getModuleJob (internal/modules/esm/loader.js:230:28)
    at Loader.import (internal/modules/esm/loader.js:165:28)
    at importModuleDynamically (internal/modules/esm/translators.js:114:35)
    at exports.importModuleDynamicallyCallback (internal/process/esm_loader.js:30:14)
    at Function.resolveName (file:///home/anelderly/wechaty-getting-started/node_modules/wechaty/src/puppet-manager.ts:118:26)
    at Function.resolve (file:///home/anelderly/wechaty-getting-started/node_modules/wechaty/src/puppet-manager.ts:72:33)
    at Wechaty.initPuppet (file:///home/anelderly/wechaty-getting-started/node_modules/wechaty/src/wechaty.ts:394:48)
    at Wechaty.start (file:///home/anelderly/wechaty-getting-started/node_modules/wechaty/src/wechaty.ts:722:18)
15:18:16 ERR Wechaty start() exception: Cannot find package 'wechaty-puppet-oicq' imported from /home/anelderly/wechaty-getting-started/node_modules/wechaty/dist/esm/src/puppet-manager.js
15:18:16 ERR StarterBot Error: Cannot find package 'wechaty-puppet-oicq' imported from /home/anelderly/wechaty-getting-started/node_modules/wechaty/dist/esm/src/puppet-manager.js

Working with WECHATY_PUPPET=wechaty-puppet-oicq still not works, any advice for further development? ESM branch code has been released to [email protected]

Register a NPM account, and prepare to publish this module to NPM

Please register an NPM account so that we can set up the CI/CD pipeline to enable DevOps with GitHub Actions.

We can do it in the next meeting of OSPP'21 project that I mentored.

After we publish the module to NPM, then the Wechaty GitHub Org can accept this repo to be transfered.

Handling breaking changes in oicq v2.x

These code should be changed to be compatible with oicq v2.x(will be released soon)

私聊消息事件中,删除了sender和user_id字段,添加了from_id和to_id字段。如果来自群还会有group_id字段。
群消息的sender字段中,不再提供sex age area。
群消息的seqid字段更名为seq。

According to https://github.com/takayama-lily/oicq/projects/3#card-70996148, this code here should
use rawPayload.from_id instead of rawPayload.sender.user_id.

fromId: String(rawPayload.sender.user_id),

This field will be missed for group message.

gender : genderStringToType[_rawPayload.sex]!,

Store `data/` data to MemoryCard and load from MemoryCard when start

Currently, OICQ will save device information (device-QQ_NUMBER.json) and token to files under the data/ folder:

$ ls -l data/
total 20
drwxr-xr-x 2 huan huan 4096 Oct  1 09:52 12345
drwxr-xr-x 2 huan huan 4096 Oct 18 01:13 3285698464
drwxr-xr-x 2 huan huan 4096 Oct 17 20:19 918999
drwxrwxr-x 2 huan huan 4096 Oct  1 09:52 image
drwxrwxr-x 2 huan huan 4096 Oct  1 09:52 record
$ ls -l data/3285698464/
total 16
-rw------- 1 huan huan 746 Oct 17 22:50 device-3285698464.json
-rw-rw-r-- 1 huan huan 520 Oct 18 01:13 qrcode.png
-rw------- 1 huan huan 112 Oct 18 20:21 t106
-rw------- 1 huan huan 288 Oct 18 20:21 token

We should save/load them to/from puppet.memory.

See: https://github.com/wechaty/puppet-wechat/blob/e34c8a1a998e045814b3dff052f74385de7a464b/src/puppet-wechat.ts#L1144-L1148

OnMessage binding using puppet works, but binding with bot in wechaty-getting-started broken

ding-dong not work if using wechaty-getting-started project with following command:

export WECHATY_PUPPET=wechaty-puppet-oicq
export WECHATY_LOG=verbose
npm start

The log inside OnMessage is never called, which means bot.on('message', onMessage) failed.

async function onMessage (msg: Message) {
  log.info('StarterBot', msg.toString())

  if (msg.text() === 'ding') {
    await msg.say('dong')
  }
}

But when directly using npm run start on wechaty-puppet-oicq project, the onMessage event is called successfully which means puppet.on('message', onMessage) works.

async function onMessage (payload: EventMessagePayload) {
  const msgPayload = await puppet.messagePayload(payload.messageId)
  if (msgPayload.text === 'ding') {
    await puppet.messageSendText(msgPayload.fromId!, 'dong')
  }
}

Any suggestion on debugging this problem?

@huan

`CQ` code parsing

The below message in QQ:

image

Will generate the below message with Puppet OICQ:

[阿布 @ QQ]: I mean in the QQ message… like this -> [CQ:at,qq=all,text=@全体成员] [CQ:face,id=187,text=幽灵]

Can we disable saving the qrcode img to file?

请用手机QQ扫描二维码,若打印出错请打开:/home/huan/git/wechaty/wechaty-getting-started/data/12345/qrcode.png

The above image file is not necessary to be created and will generate rubbish files.

Can we disable this feature for the puppet?

PuppetLoginMixin selfId() is deprecated, use `currentUserId` instead:

new error after Puppet API v0.51 upgrade eb8da77

19:31:18 WARN PuppetLoginMixin selfId() is deprecated, use `currentUserId` instead:
Error: 
    at PuppetOICQ.selfId (file:///home/anelderly/wechaty-puppet-oicq/node_modules/wechaty-puppet/src/mixins/login-mixin.ts:87:9)
    at WechatifiedMessage.talker (file:///home/anelderly/wechaty-getting-started/node_modules/wechaty/src/user/message.ts:273:69)
    at WechatifiedMessage.toString (file:///home/anelderly/wechaty-getting-started/node_modules/wechaty/src/user/message.ts:207:12)
    at Wechaty.onMessage (file:///home/anelderly/wechaty-getting-started/examples/ding-dong-bot.ts:44:30)
    at Wechaty.emit (events.js:315:20)
    at Wechaty.EventEmitter.emit (domain.js:467:12)
    at PuppetOICQ.<anonymous> (file:///home/anelderly/wechaty-getting-started/node_modules/wechaty/src/wechaty.ts:493:20)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
19:31:18 VERB PuppetLoginMixin get currentUserId()
19:31:18 INFO StarterBot Message#Text[🗣Contact<Li Dao>@👥Room<内部测试群>]      asdf

Prepare a live demo screen recording for the mid-term blog post

For your mid-term blog post, please make sure to fulfill the following requirements:

  1. Slides
    1. Embed a google slide version in your mid-term blog post
  2. Live demo
  3. Present with slides and live demo with your camera on with a zoom meeting recording video
    1. uploaded to YouTube
    2. embedded in your mid-term blog post
  4. Review your original plan, and make a new plan with the following weeks. The outcomes for each week should be defined clearly.

Please feel free to let me know if you have any questions, thank you very much.

Could not run wechaty-getting-started after use npm link

After use npm link:

[anelderly@pubgyes wechaty-getting-started]$ npm link wechaty-puppet-oicq
/home/anelderly/wechaty-getting-started/node_modules/wechaty-puppet-oicq -> /usr/lib/node_modules/wechaty-puppet-oicq -> /home/anelderly/wechaty-puppet-oicq

It seems that dist/esm missed if using npm link, any suggestion to fix it?

13:23:44 VERB PuppetManager resolveName(wechaty-puppet-oicq)
CustomError: Cannot find module '/home/anelderly/wechaty-getting-started/node_modules/wechaty-puppet-oicq/dist/esm/src/mod.js' imported from /home/anelderly/wechaty-getting-started/node_modules/wechaty/dist/esm/src/puppet-manager.js
    at finalizeResolution (/home/anelderly/wechaty-getting-started/node_modules/ts-node/dist-raw/node-esm-resolve-implementation.js:383:11)
    at moduleResolve (/home/anelderly/wechaty-getting-started/node_modules/ts-node/dist-raw/node-esm-resolve-implementation.js:818:10)
    at Object.defaultResolve (/home/anelderly/wechaty-getting-started/node_modules/ts-node/dist-raw/node-esm-resolve-implementation.js:929:11)
    at /home/anelderly/wechaty-getting-started/node_modules/ts-node/src/esm.ts:68:38
    at Generator.next (<anonymous>)
    at /home/anelderly/wechaty-getting-started/node_modules/ts-node/dist/esm.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (/home/anelderly/wechaty-getting-started/node_modules/ts-node/dist/esm.js:4:12)
    at resolve (/home/anelderly/wechaty-getting-started/node_modules/ts-node/dist/esm.js:32:16)
    at Loader.resolve (internal/modules/esm/loader.js:86:40)
    at Loader.getModuleJob (internal/modules/esm/loader.js:230:28)
    at Loader.import (internal/modules/esm/loader.js:165:28)
    at importModuleDynamically (internal/modules/esm/translators.js:114:35)
    at exports.importModuleDynamicallyCallback (internal/process/esm_loader.js:30:14)
    at Function.resolveName (file:///home/anelderly/wechaty-getting-started/node_modules/wechaty/src/puppet-manager.ts:118:26)
    at Function.resolve (file:///home/anelderly/wechaty-getting-started/node_modules/wechaty/src/puppet-manager.ts:72:33)
    at Wechaty.initPuppet (file:///home/anelderly/wechaty-getting-started/node_modules/wechaty/src/wechaty.ts:394:48)
    at Wechaty.start (file:///home/anelderly/wechaty-getting-started/node_modules/wechaty/src/wechaty.ts:722:18)
13:23:44 ERR Wechaty start() exception: Cannot find module '/home/anelderly/wechaty-getting-started/node_modules/wechaty-puppet-oicq/dist/esm/src/mod.js' imported from /home/anelderly/wechaty-getting-started/node_modules/wechaty/dist/esm/src/puppet-manager.js
13:23:44 ERR StarterBot Error: Cannot find module '/home/anelderly/wechaty-getting-started/node_modules/wechaty-puppet-oicq/dist/esm/src/mod.js' imported from /home/anelderly/wechaty-getting-started/node_modules/wechaty/dist/esm/src/puppet-manager.js

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.