Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ jobs:
# sam build
- run: sam build --use-container
# sam deploy
- run: sam deploy --no-confirm-changeset --no-fail-on-empty-changeset --parameter-overrides SlackTokenSecret=${{ secrets.SLACKTOKEN }} SmallImprovementsTokenSecret=${{ secrets.SITOKEN }} SlackChannelId=CF4U95FN0 ScheduleEnabled=true
- run: sam deploy --no-confirm-changeset --no-fail-on-empty-changeset --parameter-overrides SlackTokenSecret=${{ secrets.SLACKTOKEN }} SmallImprovementsTokenSecret=${{ secrets.SITOKEN }} SlackChannel=goals ScheduleEnabled=true
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ An Event that is triggered by a rule deployed and updated automatically by [SAM]
Serves as the main hub of this stack, deployed and updated automatically by [SAM](#sam).

- Triggered by a CloudWatch Event, which is passed into its main function.
- Assigns its Slack Channel ID via Environment variables passed in by SAM.
- Assigns its Slack Channel name via Environment variables passed in by SAM.
- Uses the SecretsManager to get both the Slack and Small Improvements tokens.
- Gets all objectives using the Small Improvements API token.
- Filters the objectives such that only those of a specific type, status, visibility, and time are left.
- Log the number of objectives found.
- For each of those objectives, the database is checked to see if it has an object with the same ID (returns a promise).
- For each of those objectives,the database is checked to see if it has an object with the same ID (returns a promise).
- If the objective was in the database, return undefined, there is nothing left to do for this objective.
- If the objective was not in the database, it will try to post to Slack, which requires the following:
- Try to get SlackID via the email address in the Small Improvements Objective.
- Format the Slack message using the objective, its status, and the SlackID.
- Format the slack message using the objective, its status, and the SlackID.
- Try to send the message (if successful, resolves to the body of the HTTP response).
- Try to insert the record of the objective into the database.
- Finally, after all of the promises created from those objectives resolve, the data on number of successful and unsuccessful posts is logged and returned.
Expand Down
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async function main(event, context) {
Post message to Slack
Put record in dynamodb
*/
const slackChannelId = process.env.SlackChannelId;
const slackChannel = process.env.SlackChannel;
const secrets = await secretsClient.getSecret();
const objectiveActivities = await smallImprovementsClient.GetObjectives(secrets.SIToken);
const { completed, created } = filter.filterActivities(objectiveActivities, new Date(event.time));
Expand All @@ -29,7 +29,7 @@ async function main(event, context) {
const SIEmail = await smallImprovementsClient.GetEmail(activity.content.objective.owner.id, secrets.SIToken);
await slackService.PostCompletedObjective(
secrets.SlackToken,
slackChannelId,
slackChannel,
activity.content,
activity.change.newStatus.description,
SIEmail
Expand All @@ -47,7 +47,7 @@ async function main(event, context) {
const SIEmail = await smallImprovementsClient.GetEmail(activity.content.objective.owner.id, secrets.SIToken);
await slackService.PostCreatedObjective(
secrets.SlackToken,
slackChannelId,
slackChannel,
activity.content,
SIEmail
);
Expand Down
8 changes: 4 additions & 4 deletions src/slack-service.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
const slackClient = require('./slack');

// Get Slack ID, Format Message, Post
async function PostCompletedObjective(token, channelId, content, newStatus, email) {
async function PostCompletedObjective(token, channelName, content, newStatus, email) {
const slackID = await slackClient.getSlackID(email, token);
const formattedMessage = await slackClient.formatSlackMessageForCompleted(content.objective, newStatus, slackID, content.cycle.id);
return await slackClient.slackPost(token, channelId, formattedMessage);
return await slackClient.slackPost(token, channelName, formattedMessage);
}
async function PostCreatedObjective(token, channelId, content, email) {
async function PostCreatedObjective(token, channelName, content, email) {
const slackID = await slackClient.getSlackID(email, token);
const formattedMessage = await slackClient.formatSlackMessageForCreated(content.objective, slackID, content.cycle.id);
return await slackClient.slackPost(token, channelId, formattedMessage);
return await slackClient.slackPost(token, channelName, formattedMessage);
}

exports.PostCompletedObjective = PostCompletedObjective;
Expand Down
4 changes: 2 additions & 2 deletions src/slack.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const messageVariables = {
};

// Post a message to a channel your app is in using ID and message text
async function slackPost(authToken, channelId, formattedMessage) { // postData should be JSON, e.g. { channel:"#channel", text:'message' }
formattedMessage.channel = '' + channelId;
async function slackPost(authToken, channelName, formattedMessage) { // postData should be JSON, e.g. { channel:"#channel", text:'message' }
formattedMessage.channel = '' + channelName;

const options = {
hostname: 'sourceallies.slack.com',
Expand Down
8 changes: 4 additions & 4 deletions template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ Parameters:
Type: String
Description: The slack token
NoEcho: true
SlackChannelId:
SlackChannel:
Type: String
Description: The id of the slack channel to post messages to
Default: C03HVBJ7WKC
Description: The name of the slack channel to post messages to
Default: si-sandbox
ScheduleEnabled:
Type: String
Description: Whether the lambda scheduled trigger is enabled or not
Expand All @@ -37,7 +37,7 @@ Resources:
Timeout: 300
Environment:
Variables:
SlackChannelId: !Ref SlackChannelId
SlackChannel: !Ref SlackChannel
Policies:
- DynamoDBCrudPolicy:
TableName: !Ref DynamoTable
Expand Down
12 changes: 6 additions & 6 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ describe('index', () => {
activities,
dynamoRecords,
objectiveId,
slackChannelId,
slackChannel,
mockEmail;

afterEach(() => {
jest.resetAllMocks();
});

beforeEach(() => {
slackChannelId = 'si-sandbox';
process.env.SlackChannelId = slackChannelId;
slackChannel = 'si-sandbox';
process.env.SlackChannel = slackChannel;

eventDateString = '2022-06-02T00:00:00Z';
event = {
Expand Down Expand Up @@ -112,7 +112,7 @@ describe('index', () => {
expect(dynamodbClient.insertRecord).toHaveBeenCalledWith(activities.items[0].items[0].activities[1], 'CREATED');
expect(slackClient.PostCompletedObjective).toHaveBeenCalledWith(
secrets.SlackToken,
slackChannelId,
slackChannel,
activities.items[0].items[0].activities[0].content,
activities.items[0].items[0].activities[0].change.newStatus.description,
mockEmail
Expand Down Expand Up @@ -147,14 +147,14 @@ describe('index', () => {
expect(dynamodbClient.insertRecord).toHaveBeenCalledWith(activities.items[0].items[0].activities[1], 'CREATED');
expect(slackClient.PostCompletedObjective).toHaveBeenCalledWith(
secrets.SlackToken,
slackChannelId,
slackChannel,
activities.items[0].items[0].activities[2].content,
activities.items[0].items[0].activities[2].change.newStatus.description,
mockEmail
);
expect(slackClient.PostCreatedObjective).toHaveBeenCalledWith(
secrets.SlackToken,
slackChannelId,
slackChannel,
activities.items[0].items[0].activities[1].content,
mockEmail
);
Expand Down
Loading