本文整理匯總了TypeScript中file-box.FileBox.fromUrl方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript FileBox.fromUrl方法的具體用法?TypeScript FileBox.fromUrl怎麽用?TypeScript FileBox.fromUrl使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類file-box.FileBox
的用法示例。
在下文中一共展示了FileBox.fromUrl方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: 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()
}
示例3: onMessage
/**
*
* 6. The most important handler is for:
* dealing with Messages.
*
*/
async function onMessage (msg: Message) {
console.log(msg.toString())
if (msg.age() > 60) {
console.log('Message discarded because its TOO OLD(than 1 minute)')
return
}
if ( msg.type() !== bot.Message.Type.Text
|| !/^(ding|ping|bing|code)$/i.test(msg.text())
/*&& !msg.self()*/
) {
console.log('Message discarded because it does not match ding/ping/bing/code')
return
}
/**
* 1. reply 'dong'
*/
await msg.say('dong')
console.log('REPLY: dong')
/**
* 2. reply image(qrcode image)
*/
const fileBox = FileBox.fromUrl('https://chatie.io/wechaty/images/bot-qr-code.png')
await msg.say(fileBox)
console.log('REPLY: %s', fileBox.toString())
/**
* 3. reply 'scan now!'
*/
await msg.say([
'Join Wechaty Developers Community\n\n',
'Scan now, because other Wechaty developers want to talk with you too!\n\n',
'(secret code: wechaty)',
].join(''))
}