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


TypeScript hubot-slack.Robot類代碼示例

本文整理匯總了TypeScript中hubot-slack.Robot的典型用法代碼示例。如果您正苦於以下問題:TypeScript Robot類的具體用法?TypeScript Robot怎麽用?TypeScript Robot使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Robot類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: is

  robot.respond(/who is (.+)/i, (response) => {
    const dataStore = robot.adapter.client.rtm.dataStore

    const userId = response.envelope.user.id
    if (!dataStore.getUserById(userId).is_admin) {
      return response.reply('Only admins can use the `who is` command')
    }

    const userName = response.match[1]
    const user = dataStore.getUserByName(userName)

    if (user) {
      const msg = JSON.stringify(user, null, 2)
      robot.send({ id: response.envelope.user.id }, {
        attachments: [{
          fallback: `\`\`\`${msg}\`\`\``,
          color: 'good',
          text: `\`\`\`${msg}\`\`\``,
          mrkdwn_in: ['text'],
        }],
      })
    } else {
      robot.send({ id: response.envelope.user.id }, `Could not find that user`)
    }
  })
開發者ID:Codesleuth,項目名稱:hubot-hackbot,代碼行數:25,代碼來源:my_id.script.ts

示例2:

  robot.error((err, response) => {
    let fallback = `Error: ${err.message}`
    let text = `\`\`\`
Error: ${err.stack}
\`\`\``

    if (response) {
      response.reply('Uhh, sorry, I just experienced an error :goberserk:')

      const user = response.envelope.user
      fallback = `Error responding to message from @${user.name}
Command: ${response.message.text}
${fallback}`
      text = `Error responding to message from @${user.name}
\`\`\`
Command: ${response.message.text}
\`\`\`
${text}`
  }

    robot.send({ room: Config.HACKBOT_ERROR_CHANNEL.value }, {
      attachments: [{
        fallback: fallback,
        color: 'warning',
        title: `Hackbot error caught`,
        text: text,
        mrkdwn_in: ['text'],
      }],
    })
  })
開發者ID:Codesleuth,項目名稱:hubot-hackbot,代碼行數:30,代碼來源:error.script.ts

示例3:

  robot.respond(/who am i/i, (response) => {
    const user = response.envelope.user

    if (user) {
      const msg = JSON.stringify(user, null, 2)
      robot.send({ id: response.envelope.user.id }, {
        attachments: [{
          fallback: `\`\`\`${msg}\`\`\``,
          color: 'good',
          text: `\`\`\`${msg}\`\`\``,
          mrkdwn_in: ['text'],
        }],
      })
    } else {
      robot.send({ id: response.envelope.user.id }, `Could not find that user`)
    }
  })
開發者ID:Codesleuth,項目名稱:hubot-hackbot,代碼行數:17,代碼來源:my_id.script.ts


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