Skip to content

Instantly share code, notes, and snippets.

@pavelvlasov
Created February 17, 2018 05:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pavelvlasov/fe08b16a556cd136306c6a4cc8dde3ab to your computer and use it in GitHub Desktop.
Save pavelvlasov/fe08b16a556cd136306c6a4cc8dde3ab to your computer and use it in GitHub Desktop.
callback(null, { body: "OK", statusCode: 200 });
const message = mentionEvent.text;
const parts = repoRegExp.exec(message);
if (parts) {
const repo = parts[1];
const params = {
FunctionName: `${stage}-getContributorStatsImage`,
InvocationType: "RequestResponse",
LogType: "Tail",
Payload: JSON.stringify({
repo
})
};
const response = await lambda.invoke(params).promise();
const payload = JSON.parse(response.Payload);
const message = {
channel: mentionEvent.channel,
text: "Contributor stats",
attachments: [
{
title: `Contributor stats for ${repo} repository`,
image_url: payload.imageUri
}
]
};
await request({
url: "https://slack.com/api/chat.postMessage",
method: "post",
json: true,
headers: {
Authorization: `Bearer ${slackToken}`,
"User-Agent": "Stats Bot for Slack"
},
body: message
});
} else {
throw new Error("Can not recognize repository name");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment