Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support QQ Group message receive & send #13

Closed
Tracked by #12
huan opened this issue Oct 13, 2021 · 14 comments
Closed
Tracked by #12

Support QQ Group message receive & send #13

huan opened this issue Oct 13, 2021 · 14 comments
Labels
enhancement New feature or request

Comments

@huan
Copy link
Member

huan commented Oct 13, 2021

If we use Wechaty to manage our QQ group, we need to support the QQ group message receiving & sending.

Reference source code:

https://github.com/wechaty/wechaty-puppet-wechat/blob/a45a4ab7e20bb9cfc328e904966a550dbdc8e3a0/src/pure-function-helpers/message-raw-payload-parser.ts#L21-L41

Link to

@huan
Copy link
Member Author

huan commented Oct 17, 2021

messageSendText(conversationId, text) is using for both Contact.say and Room.say.

Please refer to the below example code and feel free to let me know your questions by replying to this issue.

Send room message code example

  1. Wechaty Room source code at here
  2. Puppet Wechaty messageSendText source code at here

@anaivebird
Copy link
Collaborator

how to tell Room.say from Contact.say, since QQ group number and QQ account number can be same?

@anaivebird
Copy link
Collaborator

roomRawPayload and roomRawPayloadParser has been implemented, and room name of a room message could be shown in terminal.

17:47:11 INFO StarterBot Message#Text[🗣Contact<Li Dao>@👥Room<内部测试群>]      ding
17:47:11 VERB Message say(dong)
17:47:11 VERB Puppet selfId()
17:47:11 VERB Puppet selfId()
17:47:11 VERB Message mentionList()
17:47:11 VERB Message mentionList() text = "ding", mentionNameList = "[]"
17:47:17 VERB Message static load(LaGHkzKIqqUAAAAunlM4/2Fr8SUB)
17:47:17 VERB Message constructor(LaGHkzKIqqUAAAAunlM4/2Fr8SUB) for class WechatifiedMessage
17:47:17 VERB Message ready()
17:47:17 VERB Puppet messagePayload(LaGHkzKIqqUAAAAunlM4/2Fr8SUB)
17:47:17 VERB Room ready()
17:47:17 VERB Puppet selfId()
17:47:17 INFO StarterBot Message#Text[🗣Contact<Li Dao>@👥Room<内部测试群>]      asdf

@anaivebird
Copy link
Collaborator

If someone say message in group, and he is not a friend of the bot. contactRawPayload could not find contact info from this.contactStore.

To fix this problem. We will add a person's info to this.contactStore after he says something in group if he is not a friend of bot.

@huan
Copy link
Member Author

huan commented Oct 17, 2021

how to tell Room.say from Contact.say, since QQ group number and QQ account number can be same?

Have you got the solutions to it? Our current design in Puppet API is using a conversationId for both contact and room.

roomRawPayload and roomRawPayloadParser has been implemented, and room name of a room message could be shown in terminal.

That's great, good job!

To fix this problem. We will add a person's info to this.contactStore after he says something in the group if he is not a friend of the bot.

My suggestion is to use the puppet.roomMemberPayload related API for contact payloads who are not friends of the bot but in a QQ group / WeChat room. You can refer to the WeChat Web puppet at here

@anaivebird
Copy link
Collaborator

Group ding dong succeeded!

how to tell Room.say from Contact.say, since QQ group number and QQ account number can be same?
Have you got the solutions to it? Our current design in Puppet API is using a conversationId for both contact and room.

Currently, the puppet will check if conversationId is in bot account's added group list. If bot has join group of conversationId, it will send the message to the group. Otherwise, a private message will be sent to qq of conversationId.
image

@huan
Copy link
Member Author

huan commented Oct 17, 2021

Congratulations!

Could you please help us to confirm the QQ account provided by @krapnikkk can work with our QQ ding/dong bot?

If we can have the QQ account worked, then I believe we can try to integrate our Friday BOT with QQ soon!

Currently, the puppet will check if a conversation is in the bot account's added group list. If the bot has joined the group of conversationId, it will send the message to the group. Otherwise, a private message will be sent to QQ of conversationId.

It's a good workaround. I hope we can find a way to deal with it better in the future.

@huan huan reopened this Oct 22, 2021
@huan
Copy link
Member Author

huan commented Oct 22, 2021

I reopen this issue because we need to improve the puppet code to better deal with the oicq protocol.

According to this link, the QQ number and the group number might be exactly the same.

This is a challenge of our current puppet design: we are using a conversationId for sending messages to, which means we need to differentiate the number of QQ and the Group.

For example, we can add a prefix to achieve that:

  1. qq_xxx means qq user number
  2. group_xxx means qq group number

We can do the conversion inside the puppet-oicq from and to the OICQ.

Please feel free to let me know if you have any questions and good ideas.

@anaivebird
Copy link
Collaborator

Got it. I try to change to this pattern, a problem is:
If someone says ding on Group, puppet will be called with conversationId=qq_xxx in messageSendText, and bot will send dong to this people by private message instead of in group, is it expected?

@anaivebird
Copy link
Collaborator

anaivebird commented Oct 23, 2021

I found that if we use ding-dong bot of wechaty-getting-started, bot will reply dong on QQ group.

Because it called msg.say('dong')

If we use run the puppet directly, bot will reply dong to the person in private message, for it called await puppet.messageSendText(msgPayload.fromId!, 'dong')

@anaivebird
Copy link
Collaborator

anaivebird commented Oct 23, 2021

I reopen this issue because we need to improve the puppet code to better deal with the oicq protocol.

According to this link, the QQ number and the group number might be exactly the same.

This is a challenge of our current puppet design: we are using a conversationId for sending messages to, which means we need to differentiate the number of QQ and the Group.

For example, we can add a prefix to achieve that:

  1. qq_xxx means qq user number
  2. group_xxx means qq group number

We can do the conversion inside the puppet-oicq from and to the OICQ.

Please feel free to let me know if you have any questions and good ideas.

I think commit ae0053e has implemented all of these. And wechaty-puppet-oicq@0.3.6 is released.

fromId and roomId has been changed as asked above.

{"fromId":"qq_1962099319","id":"dPNCdwAAAAll+k9fYXPYZQE=","text":"Wechaty login","timestamp":1634981990088,"type":7,"toId":"qq_1962099319"}
{"fromId":"qq_847817381","id":"LaGHkzKIqqUAAABWzeCF12Fz2GcB","text":"ding","timestamp":1634981991493,"type":7,"roomId":"group_765560723"}

@huan
Copy link
Member Author

huan commented Oct 23, 2021

The code looks good, I believe the problem of that qq and group number can be same can be solved with our latest version of the code.

@anaivebird
Copy link
Collaborator

anaivebird commented Oct 23, 2021

The code looks good, I believe the problem of that qq and group number can be same can be solved with our latest version of the code.

I think the problem is of course solved with this commit, because we dispatch private and group message send by prefix group_ or qq_

https://github.com/wechaty/puppet-oicq/blob/main/src/puppet-oicq.ts#L237-L249

@huan
Copy link
Member Author

huan commented Oct 23, 2021

Of course.

Thank you very much for the clarifying!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants