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

Receive and send audio messages #21

Merged
merged 9 commits into from
Feb 18, 2021
Merged

Receive and send audio messages #21

merged 9 commits into from
Feb 18, 2021

Conversation

zhangfand
Copy link
Contributor

@zhangfand zhangfand commented Feb 7, 2021

Fixes #19

The change adds support to OA puppet to receive and send audio files from / to Wechat,
and add another example that "echo" text or audio messages.

The implementation is largely constructed per the detailed instructions in #19 (❤️ ) .
There are a few catches:

  1. Have to make messageSend public and use it in the example instead of using messageSendFile. The main reason is mime package can not infer MIME type of amr file extension.
  2. How Wechat /get/media API handles audio file is not well documented. From experiments, it seems to always return the audio file. I've documented the assumed format in the code.

@CLAassistant
Copy link

CLAassistant commented Feb 7, 2021

CLA assistant check
All committers have signed the CLA.

@zhangfand zhangfand changed the title Receive and send audio message Receive and send audio messages Feb 7, 2021
Copy link
Member

@huan huan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your PR looks great, it has implemented most of the code for supporting the audio message for the OA puppet!

However, there has two parts of the code that we need to improve before we can merge it.

Please see my review at #19 (comment)

Copy link
Member

@huan huan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update!

Please see my reviews for some minor questions.

And for better unit testing, I believe the best practice is to build a Mock HTTP Server to interact with the code, and make sure our code is behavior as expected.

examples/echo.ts Outdated
if (payload.qrcode) {
// Generate a QR Code online via
// http://goqr.me/api/doc/create-qr-code/
const qrcodeImageUrl = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/wechaty/wechaty-getting-started/blob/7c3ebd90f4b8cb7f22bf49ca419debbdde275437/examples/ding-dong-bot.ts#L21-L24

Please use our wechaty.js.org to generate the online qrcode. because the qrserver.com is too slow and always out of service.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the comment below. TL;DR I deleted it in the newest commit.

examples/echo.ts Outdated Show resolved Hide resolved
examples/echo.ts Outdated
*/
async function onMessage (event: EventMessagePayload) {
const payload = await puppet.messagePayload(event.messageId);
const fileBox = await puppet.messageFile(event.messageId)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The payload might not a file type.

What if a user just sends a text to the official account?

Need to be checked.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. I updated the code to handle different types of messages.

@zhangfand
Copy link
Contributor Author

Replied to questions in the code review.

Copy link
Member

@huan huan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this PR will be ready to merge after the CI turns green.

Please fix the lining problems, thanks!

@wj-Mcat
Copy link
Contributor

wj-Mcat commented Feb 18, 2021

Kindly ping @zhangfand

@zhangfand
Copy link
Contributor Author

zhangfand commented Feb 18, 2021

The newest mime package adds extentions mapping for audio/amr, which causes initialization failure in file-box (see failed test log).

huan/file-box#53 should fix the issue. Once that is merged, I can upgrade dependency version as part of the PR.

@huan
Copy link
Member

huan commented Feb 18, 2021

Dove. Thank you very much for keeping the modules update!

Copy link
Member

@huan huan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@huan huan merged commit 0960b9c into wechaty:master Feb 18, 2021
@huan
Copy link
Member

huan commented Feb 18, 2021

Thank you very much for your contribution!

You are welcome to join Wechaty Contributor Program

1. Join Wechaty Organization

You've invited Zhangfan to Wechaty! They'll be receiving an email shortly. They can also visit https://github.com/wechaty to accept the invitation.

I have invited you to join our Wechaty GitHub Organization, please accept it by following the above message.

2. Update Your Wechaty Contributor Profile

  1. Please open Contributor Hall of Fame and add yourself to the end of the list, so that other contributors will know you better!
  2. Please add yourself to our Website Contributors by creating a PR and refer to this PR link as well.

3. Join The Contributor Only WeChat Room

We also have a WeChat room for contributors only which can discuss Wechaty at a deeper level, you are welcome to join and if you are interested.

Please add @lijiarui wechat: ruirui_0914 and send her this pr link. She will invite you into Wechaty Contributor Room

Cheers!

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.

Feature request: receive and send audio message
4 participants