當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript FileBox.fromUrl方法代碼示例

本文整理匯總了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
  }
開發者ID:miggame,項目名稱:wechaty,代碼行數:35,代碼來源:puppet-padchat.ts

示例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()
  }
開發者ID:miggame,項目名稱:wechaty,代碼行數:11,代碼來源:puppet-mock.ts

示例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(''))
}
開發者ID:KiddoLin,項目名稱:wechaty,代碼行數:45,代碼來源:ding-dong-bot.ts


注:本文中的file-box.FileBox.fromUrl方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。