Skip to content

Conversation

hcfw007
Copy link
Member

@hcfw007 hcfw007 commented May 9, 2023

WHAT

πŸ€– Generated by Copilot at c398075

Added a reply method to MessageMixin to support replying to messages. The method uses the wechaty-puppet Post type to create and send the reply.
​

πŸ€– Generated by Copilot at c398075

Sing, O Muse, of the skillful MessageMixin,
That grants the power of reply to the swift messages,
As they fly through the air like winged arrows of Apollo,
Or like Hermes, who bears the golden staff of Post.

WHY

HOW

πŸ€– Generated by Copilot at c398075

  • Import Post type from wechaty-puppet to use for replying messages (link)
  • Add reply method to MessageMixin class to allow a message to reply to another message with various content types (link)

#2387

syntactic sugar for

wechaty.on('message', async msg => {
	const messagePost = msg.toPost()
	const post = bot.Post.builder()
	post.add('This is reply msg')
	post.reply(messagePost)
	post.type(PostType.Message)
	message.say(await post.build())
})

@huan
Copy link
Member

huan commented Jul 2, 2023

I found a design mismatch in the Message.reply() and Post.reply():

Problem

Let's say:

  1. the Parent is the post/message we are replying to
  2. the Child is the reply we created as the response

Post.reply

In post.reply(arg):

  1. the post is Child
  2. the arg is Parent
wechaty.on('message', async msg => {
	const messagePost = msg.toPost()
	const post = bot.Post.builder()
	post.add('This is reply msg')
	post.reply(messagePost)
	post.type(PostType.Message)
	message.say(await post.build())
})

Message.reply

In message.reply(arg):

  1. the message is Parent
  2. the arg is Cihld
wechaty.on('message', async msg => {
	await message.reply('This is a reply msg')
})

Solution

They should be the same semantics when calling reply(); we must change one to align with the other.

Can we answer the following question first, and find 3-5 developers to collect their answers, so that we can make the final decision:

  1. message.reply(arg): who is reply to who?
    1. message reply to arg
    2. arg reply to message
  2. post.reply(arg): who is reply to who?
    1. post reply to arg
    2. arg reply to post

For the first question, I think the only choice is 2: arg reply to message because the arg is a Sayable and has no reply() method.

So the final design should change the Post.reply design to use arg to reply to the post.

Conslusion

Before (the wrong design)

Parent Child
message.reply(argSayable) message argSayable
post.reply(argPost) argPost post

After (the correct design)

Parent Child
message.reply(argSayable) message argSayable
post.reply(argPost) post argPost

@huan
Copy link
Member

huan commented Jul 15, 2023

Any comments?

It would be great if you can send a PR to modify this because you can make sure every API is correct.

Or I will do it later next week.

Thanks!

@hcfw007
Copy link
Member Author

hcfw007 commented Jul 17, 2023

Any comments?

It would be great if you can send a PR to modify this because you can make sure every API is correct.

Or I will do it later next week.

Thanks!

In my oppinion, originalMessage.reply(args) means to send a new message with args replying to the originalMessage.

Because the originalMessage here is the instance of message representing an actual message in the IM.

postBuilder.reply(args) mens set the post to reply to the args.

The post builder here is the builder intance inside wechaty creating a new message.

@huan
Copy link
Member

huan commented Jul 17, 2023

I can not understand. Can you explain more in details?

@huan huan closed this Jul 17, 2023
@hcfw007
Copy link
Member Author

hcfw007 commented Jul 17, 2023

In my mind, the scenario is this:

bot.on('message', async (message) => {
  await message.reply('replied message')
})

So when I call reply on a message instance, I was actually replyting to the message, thus I want to quote the original message with the new messages in args. The object I am handling is the original message.

When building a post with PostBuilder, the object I am handling is the new post. So I want the new message to quote the message in the args.

const builder = bot.Post.builder()
builder.add('some message')
builder.reply(message)
const post = await builder.build()

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

Successfully merging this pull request may close these issues.

2 participants