auths
objectreturn
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps, params) => {
}
const _ = require('lodash')
const mention = {
issueNumber: '',
issueTitle: '',
issueUrl: '',
found: false,
label: '',
type: '',
by: '',
content: '',
notification: ''
}
mention.issueNumber = event.body.issue.number
mention.issueTitle = event.body.issue.title
mention.issueUrl = event.body.issue.url
if (_.get(event, 'body.action', '') === 'opened') {
//process new issues -- check if username was mentioned in issue body
console.log(event.body.issue.body)
if (_.get(event,'body.issue.body','').includes(`@${params.github_username}`) === true) {
//user was mentioned in the description of a new issue
mention.found = true
mention.label = 'issue description'
mention.type = 'new issue'
mention.by = _.get(event, 'body.issue.user.login', '')
mention.content = _.get(event,'body.issue.body','')
} else {
//if the wasn't mentioned in the description,
//there should be no mention since this was a new issue
mention.found = false
}
} else {
//process existing issues
//first, check if the issue body was
if (_.get(event,'body.changes','') !== '' && _.get(event,'body.issue.body','').includes(`@${params.github_username}`) === true) {
//the body was modified and the user is mentioned
//check if the original issue body mentioned the user
if (_.get(event,'body.changes.body.from','').includes(`@${params.github_username}`) ._
=== true) {
//user was mentioned in the original body, but the content was updated
mention.found = true
mention.label = 'issue description'
mention.type = 'content modified'
mention.by = _.get(event, 'body.issue.user.login', '')
mention.content = _.get(event,'body.issue.body','')
} else {
//user was not previously mentioned in the issue body
mention.found = true
mention.label = 'issue description'
mention.type = 'new mention'
mention.by = _.get(event, 'body.issue.user.login', '')
mention.content = _.get(event,'body.issue.body','')
}
} else {
//the user wasn't mentioned in the body
//check if username was mentioned in issue comment
if (_.get(event,'body.comment.body','').includes(`@${params.github_username}`) ._
=== true) {
mention.found = true
mention.label = 'comment'
mention.type = 'new mention'
mention.by = _.get(event, 'body.comment.user.login', '')
mention.content = _.get(event,'body.comment.body','')
} else {
//the user wasn't mentioned in the comment
mention.found = false
}
}
}
if(mention.found === true) {
//construct the notification
mention.notification = `*@${mention.by}* mentioned you `
+ `on Github: ${mention.content} `
+ `(Issue #${mention.issueNumber}:`
+ `${mention.issueTitle} ${mention.issueUrl})`
}
return mention
auths
objectreturn
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps) => {
}
if (steps.detect_mention.found !== true) {
$end('User not mentioned')
}
Channel, private group, or IM channel to send message to. Can be an encoded ID, or a name. See below for more details.
Text of the message to send. See below for an explanation of formatting. This field is usually required, unless you're providing only attachments instead. Provide no more than 40,000 characters or risk truncation.
async
(params, auths) => {
}
const data = {
channel: params.channel,
text: params.text,
as_user: params.as_user,
attachments: params.attachments,
blocks: params.blocks,
icon_emoji: params.icon_emoji,
icon_url: params.icon_url,
link_names: params.link_names,
mrkdwn: params.mrkdwn,
parse: params.parse,
reply_broadcast: params.reply_broadcast,
thread_ts: params.thread_ts,
unfurl_links: params.unfurl_links,
unfurl_media: params.unfurl_media,
username: params.username,
}
const config = {
method: "post",
url: `https://slack.com/api/chat.postMessage`,
headers: {
Authorization: `Bearer ${auths.slack.oauth_access_token}`,
},
data,
}
return await require("@pipedreamhq/platform").axios(this, config)