generated from wechaty/puppet-mock
-
Notifications
You must be signed in to change notification settings - Fork 7
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
enable sending voice message through messageSendFile() #20
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,7 @@ import { | |
import { | ||
OAContactPayload, | ||
OAMessagePayload, | ||
OAMediaType, | ||
} from './official-account/schema' | ||
|
||
export type PuppetOAOptions = PuppetOptions & Partial<OfficialAccountOptions> | ||
|
@@ -152,7 +153,6 @@ class PuppetOA extends Puppet { | |
|
||
public async start (): Promise<void> { | ||
log.verbose('PuppetOA', 'start()') | ||
|
||
if (this.state.on()) { | ||
log.warn('PuppetOA', 'start() is called on a ON puppet. await ready(on) and return.') | ||
await this.state.ready('on') | ||
|
@@ -161,7 +161,6 @@ class PuppetOA extends Puppet { | |
|
||
try { | ||
this.state.on('pending') | ||
|
||
this.oa = new OfficialAccount({ | ||
appId : this.appId, | ||
appSecret : this.appSecret, | ||
|
@@ -170,7 +169,6 @@ class PuppetOA extends Puppet { | |
token : this.token, | ||
webhookProxyUrl : this.webhookProxyUrl, | ||
}) | ||
|
||
// FIXME: Huan(202008) find a way to get the bot user information | ||
// Official Account Info can be customized by user, so It should be | ||
// configured by environment variable. | ||
|
@@ -179,9 +177,7 @@ class PuppetOA extends Puppet { | |
await this.oa.payloadStore.setContactPayload(this.id, { openid: this.id } as any) | ||
|
||
this.bridgeEvents(this.oa) | ||
|
||
await this.oa.start() | ||
|
||
this.state.on(true) | ||
} catch (e) { | ||
log.error('PuppetOA', 'start() rejection: %s', e) | ||
|
@@ -495,6 +491,7 @@ class PuppetOA extends Puppet { | |
private async messageSend ( | ||
conversationId: string, | ||
something: string | FileBox, // | Attachment | ||
mediatype: OAMediaType = 'image' | ||
): Promise<string> { | ||
log.verbose('PuppetOA', 'messageSend(%s, %s)', conversationId, something) | ||
if (!this.id) { | ||
|
@@ -516,7 +513,7 @@ class PuppetOA extends Puppet { | |
msgId = await this.oa?.sendCustomMessage(payload) | ||
} | ||
} else if (something instanceof FileBox) { | ||
await this.oa?.sendFile({ file: something, msgtype: 'image', touser: conversationId }) | ||
await this.oa?.sendFile({ file: something, msgtype: mediatype, touser: conversationId }) | ||
} | ||
if (!msgId) { | ||
throw new Error('PuppetOA messageSend() can"t get msgId response') | ||
|
@@ -535,7 +532,8 @@ class PuppetOA extends Puppet { | |
conversationId: string, | ||
file : FileBox, | ||
): Promise<string> { | ||
return this.messageSend(conversationId, file) | ||
const msgtype: OAMediaType = (file.mimeType === 'image/jpeg') ? 'image' : 'voice' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we make this logic more robust? I'd like to suggest that:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks for the suggestions, have updated |
||
return this.messageSend(conversationId, file, msgtype) | ||
} | ||
|
||
public async messageSendContact ( | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep this log verbose output, because we always log a function when it's being called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, i uncommented it. just to note that this line does not work for audio file such as .mp3, and will throw an error.