本文整理汇总了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;未经允许,请勿转载。 |
请发表评论