本文整理汇总了TypeScript中hubot-slack.Robot.send方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Robot.send方法的具体用法?TypeScript Robot.send怎么用?TypeScript Robot.send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hubot-slack.Robot
的用法示例。
在下文中一共展示了Robot.send方法的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`)
}
})
示例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'],
}],
})
})
示例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`)
}
})