我正在尝试编写一个Hubot侦听器,该侦听器将根据特定的聊天对话自动创建JIRA问题。这是示例(我从此处使用https://github.com/RocketChat/hubot-rocketchat-boilerplate的Hubot-Rocketchat样板代码)
module.exports = (robot) => {
robot.hear(/^#alerts (.*)/i, (res) => {
const jiraurl="https://jira.example.com/rest/api/2/issue/"
const jiraproject="ALERTS"
text = res.match[1]
data = JSON.stringify({
"fields": {
"project":
{
"key": `#{jiraproject}`
},
"summary": `#{text}`,
"description": "Задача создана автоматически из RocketChat",
"issuetype": {
"name": "Инцидент"
}
}
})
/* res.reply(data) */
res.reply(`Создаю задачу в JIRA: ${text}`)
robot.http(jiraurl)
.header('Content-Type', 'application/json')
.post(data) (err, response, body) =>
if err
res.send `Ошибка: #{err}`
return
})
}
执行此操作的正确方法是什么?