Skip to content

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

Open

Description

@Hyfred

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的话怎么在被添加好友之后自动触发 发送小程序呢。

Activity

  1. wj-Mcat commented on Jul 4, 2022

    @wj-Mcat
    Collaborator

    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
  2. Hyfred commented on Jul 4, 2022

    @Hyfred
    Author

    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)

  3. wj-Mcat commented on Jul 5, 2022

    @wj-Mcat
    Collaborator

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions