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

关于发送小程序的一个疑问。添加好友申请通过自动发送小程序。 #81

Open
Hyfred opened this issue Jul 4, 2022 · 3 comments

Comments

@Hyfred
Copy link

Hyfred commented Jul 4, 2022

if msg.text() == 'test': mini_program_json = {'appid': 'wx7', 'description': '', 'pagePath': None, 'thumbKey': '', 'iconUrl': '', 'thumbUrl': None, 'shareId': '0_wx728d67143_0', 'title': '', 'username': 'gh_dd@app'} loaded_uu_mini_program = self.MiniProgram.create_from_json(payload_data=mini_program_json) await msg.say(loaded_uu_mini_program) # await from_contact.say(loaded_uu_mini_program)

亲测这段模版是能发送小程序的,但是我有两个疑问就是
1.为什么这里是msg.say,而不是from_contact.say(我定义了from_contact = msg.talker())。
2.如果是msg.say的话怎么在被添加好友之后自动触发 发送小程序呢。

@wj-Mcat
Copy link
Collaborator

wj-Mcat commented Jul 4, 2022

Answer:

  1. If the message is from room, it will say something to the room, if the message is not from room, but contact, it will say something to the contact.
  2. you can load the new friend, and say something to the contact, you can refer to: https://github.com/wechaty/python-wechaty-getting-started/blob/master/examples/advanced/friendship-bot.py#L54

@Hyfred
Copy link
Author

Hyfred commented Jul 4, 2022

Answer:

  1. If the message is from room, it will say something to the room, if the message is not from room, but contact, it will say something to the contact.
  2. you can load the new friend, and say something to the contact, you can refer to: https://github.com/wechaty/python-wechaty-getting-started/blob/master/examples/advanced/friendship-bot.py#L54

But when we receive the friendship application, we only get the friendship or hallo_word(FriendshipType.FRIENDSHIP_TYPE_RECEIVE as the link you send). There are no 'msg', so if I use msg.say(mini programme), It does not work.

So If I want to indicate a new friend and send the mini programme or photo to him, how can I do that? (Not send because of the keyword activation)

@wj-Mcat
Copy link
Collaborator

wj-Mcat commented Jul 5, 2022

All of Room, Contact and Message instance contains the say method which handle the message sending operation.

msg only appear in on_message event, so you can use msg.say to handle the message sending operation. If you handle the message sending in on_friendship event, you can use the contact.say to send message.

It's not the meaning that alway using msg.say to send message, you can use different module in different situation.

Hope that can help you. Please feel free tell us more about your problem.

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

No branches or pull requests

2 participants