本文整理汇总了TypeScript中file-box.FileBox类的典型用法代码示例。如果您正苦于以下问题:TypeScript FileBox类的具体用法?TypeScript FileBox怎么用?TypeScript FileBox使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FileBox类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: contactAvatar
public async contactAvatar(contactId: string, file?: FileBox): Promise<void | FileBox> {
log.verbose('PuppetPadchat', 'contactAvatar(%s%s)',
contactId,
file ? (', ' + file.name) : '',
)
/**
* 1. set avatar for user self
*/
if (file) {
if (contactId !== this.selfId()) {
throw new Error('can not set avatar for others')
}
if (!this.padchatManager) {
throw new Error('no padchat manager')
}
await this.padchatManager.WXSetHeadImage(await file.toBase64())
return
}
/**
* 2. get avatar
*/
const payload = await this.contactPayload(contactId)
if (!payload.avatar) {
throw new Error('no avatar')
}
const fileBox = FileBox.fromUrl(
payload.avatar,
`wechaty-contact-avatar-${payload.name}.jpg`,
)
return fileBox
}
示例2: messageFile
/**
*
* Message
*
*/
public async messageFile(messageId: string): Promise<FileBox> {
log.warn('PuppetPadchat', 'messageFile(%s)', messageId)
if (!this.padchatManager) {
throw new Error('no padchat manager')
}
const rawPayload = await this.messageRawPayload(messageId)
const payload = await this.messagePayload(messageId)
const rawText = JSON.stringify(rawPayload)
const attachmentName = payload.filename || payload.id
let result
switch (payload.type) {
case MessageType.Audio:
result = await this.padchatManager.WXGetMsgVoice(rawText)
console.log(result)
return FileBox.fromBase64(result.voice, `${attachmentName}.slk`)
case MessageType.Emoticon:
result = await this.padchatManager.WXGetMsgEmoticon(rawText)
console.log(result)
return FileBox.fromBase64(result.image, `${attachmentName}.gif`)
case MessageType.Image:
result = await this.padchatManager.WXGetMsgImage(rawText)
console.log(result)
return FileBox.fromBase64(result.image, `${attachmentName}.jpg`)
case MessageType.Video:
result = await this.padchatManager.WXGetMsgVideo(rawText)
console.log(result)
return FileBox.fromBase64(result.video, `${attachmentName}.mp4`)
case MessageType.Attachment:
default:
log.warn('PuppetPadchat', 'messageFile(%s) unsupport type: %s(%s) because it is not fully implemented yet, PR is welcome.',
messageId,
PadchatMessageType[rawPayload.sub_type],
rawPayload.sub_type,
)
const base64 = 'Tm90IFN1cHBvcnRlZCBBdHRhY2htZW50IEZpbGUgVHlwZSBpbiBNZXNzYWdlLgpTZWU6IGh0dHBzOi8vZ2l0aHViLmNvbS9DaGF0aWUvd2VjaGF0eS9pc3N1ZXMvMTI0OQo='
const filename = 'wechaty-puppet-padchat-message-attachment-' + messageId + '.txt'
const file = FileBox.fromBase64(
base64,
filename,
)
return file
}
}
示例3: messageSendFile
public async messageSendFile(
receiver : Receiver,
file : FileBox,
): Promise<void> {
log.verbose('PuppetWechat4u', 'messageSend(%s, %s)', receiver, file)
// room first
const id = receiver.roomId || receiver.contactId
if (!id) {
throw new Error('no id')
}
/**
* 通过表情MD5发送表情
*/
// wechat4u.sendMsg({
// emoticonMd5: '00c801cdf69127550d93ca52c3f853ff'
// }, ToUserName)
// .catch(err => {
// bot.emit('error', err)
// })
/**
* 以下通过上传文件发送图片,视频,附件等
* 通用方法为入下
* file为多种类型
* filename必填,主要为了判断文件类型
*/
await this.wechat4u.sendMsg({
file : await file.toStream(),
filename : file.name,
}, id)
}
示例4: emitLoginQrcode
protected async emitLoginQrcode(): Promise<void> {
log.verbose('PuppetPadchatManager', `emitLoginQrCode()`)
if (this.loginScanQrcode) {
throw new Error('qrcode exist')
}
const result = await this.WXGetQRCode()
if (!result || !result.qr_code) {
log.verbose('PuppetPadchatManager', `emitLoginQrCode() result not found. Call WXInitialize() and try again ...`)
await this.WXInitialize()
// wait 1 second and try again
await new Promise(r => setTimeout(r, 1000))
return await this.emitLoginQrcode()
}
const fileBox = FileBox.fromBase64(result.qr_code, 'qrcode.jpg')
const qrcodeDecoded = await fileBoxToQrcode(fileBox)
this.loginScanQrcode = qrcodeDecoded
this.loginScanStatus = WXCheckQRCodeStatus.WaitScan
this.emit(
'scan',
this.loginScanQrcode,
this.loginScanStatus,
)
}
示例5: roomAvatar
public async roomAvatar(roomId: string): Promise<FileBox> {
log.verbose('PuppetMock', 'roomAvatar(%s)', roomId)
const payload = await this.roomPayload(roomId)
if (payload.avatar) {
return FileBox.fromUrl(payload.avatar)
}
log.warn('PuppetMock', 'roomAvatar() avatar not found, use the chatie default.')
return qrCodeForChatie()
}
示例6: messageSendFile
public async messageSendFile(
receiver : Receiver,
file : FileBox,
): Promise<void> {
log.verbose('PuppetPadchat', 'messageSend("%s", %s)', JSON.stringify(receiver), file)
// Send to the Room if there's a roomId
const id = receiver.roomId || receiver.contactId
if (!id) {
throw new Error('no id!')
}
if (!this.padchatManager) {
throw new Error('no padchat manager')
}
const type = file.mimeType || path.extname(file.name)
switch (type) {
case '.slk':
// 发送语音消息(微信silk格式语音)
await this.padchatManager.WXSendVoice(
id,
await file.toBase64(),
60,
)
break
default:
await this.padchatManager.WXSendImage(
id,
await file.toBase64(),
)
break
}
}
示例7: contactAvatar
public async contactAvatar(contactId: string, file?: FileBox): Promise<void | FileBox> {
log.verbose('PuppetMock', 'contactAvatar(%s)', contactId)
/**
* 1. set
*/
if (file) {
return
}
/**
* 2. get
*/
const WECHATY_ICON_PNG = path.resolve('../../docs/images/wechaty-icon.png')
return FileBox.fromFile(WECHATY_ICON_PNG)
}
示例8: test
test('imageBase64ToQrCode()', async t => {
const QRCODE_IMAGE_BASE64 = [
'iVBORw0KGgoAAAANSUhEUgAAAMgAAADIAQMAAACXljzdAAAABlBMVEX///8AAABVwtN+AAAA',
'CXBIWXMAAA7EAAAOxAGVKw4bAAAA7klEQVRYw+2WsQ3EIAxFjShSMgKjZLRktIzCCJQpIv7Z',
'hCiXO/qzT/wCWXo0X3wbEw0NWVaEKM187KHW2QLZ+AhpXovfQ+J6skEWHELqBa5NEeCwR7iS',
'V7BDzuzAiZ9eqn5IWjfWXHf7VCO5tPAM6U9AjSRideyHFn4FiuvDqV5CM9rZXuF2pZmIAjZy',
'x4S0MDdBxEmu3TrliPf7iglPvuLlRydfU3P70UweCSK+ZYK0mUg1O4AVcv0/8itGkC7SdiTH',
'0+Mz19oJZ4NkhhSPbIhQkQGI8u1HJzmzs7p7pzNAru2pJb6z8ykkQ0P/pheK6vjurjf7+wAA',
'AABJRU5ErkJggg==',
].join('')
const EXPECTED_QRCODE_TEXT = 'hello, world!'
const file = FileBox.fromBase64(QRCODE_IMAGE_BASE64, 'hello.png')
const text = await fileBoxToQrcode(file)
t.equal(text, EXPECTED_QRCODE_TEXT, 'should decode qrcode image base64')
})
示例9: roomQrcode
public async roomQrcode(roomId: string): Promise<string> {
log.verbose('PuppetPadchat', 'roomQrcode(%s)', roomId)
const memberIdList = await this.roomMemberList(roomId)
if (!memberIdList.includes(this.selfId())) {
throw new Error('userSelf not in this room: ' + roomId)
}
const base64 = await this.padchatManager!.WXGetUserQRCode(roomId, 0)
const roomPayload = await this.roomPayload(roomId)
const roomName = roomPayload.topic || roomPayload.id
const fileBox = FileBox.fromBase64(base64, `${roomName}-qrcode.jpg`)
const qrcode = await fileBoxToQrcode(fileBox)
return qrcode
}
示例10: contactAvatar
public async contactAvatar(contactId: string, file?: FileBox): Promise<void | FileBox> {
log.verbose('PuppetWechat4u', 'contactAvatar(%s)', contactId)
if (file) {
throw new Error('not supported')
}
const rawPayload = await this.contactRawPayload(contactId)
const res = await this.wechat4u.getHeadImg(rawPayload.HeadImgUrl)
/**
* 如何获取联系人头像
*/
return FileBox.fromStream(
res.data,
`${contactId}.jpg`, // FIXME
)
}