-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from fossamagna/add-slack-app
feat: add slack app as selection to receive amplify notification
- Loading branch information
Showing
11 changed files
with
342 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,5 +7,7 @@ | |
"version", | ||
"help" | ||
], | ||
"eventHandlers": [] | ||
"eventHandlers": [ | ||
"PostPush" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
packages/amplify-category-console-notification/src/event-handlers/handle-PostPush.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { $TSContext, $TSMeta } from 'amplify-cli-core'; | ||
import { category } from '../constants'; | ||
|
||
export const run = async (context: $TSContext) => { | ||
const previousFunctionUrlByServiceName = getFunctionUrlBySerivceName(context.exeInfo.amplifyMeta); | ||
const { outputsByCategory } = context.amplify.getResourceOutputs(); | ||
Object.entries<Record<string, string>>(outputsByCategory[category]) | ||
.filter(([_, output]) => !!output.LambdaFunctionUrl) | ||
.filter(([serviceName, output]) => previousFunctionUrlByServiceName[serviceName] !== output.LambdaFunctionUrl) | ||
.forEach(([serviceName, output]) => { | ||
showFunctionUrlInformation(context, serviceName, output.LambdaFunctionUrl); | ||
}); | ||
}; | ||
|
||
function showFunctionUrlInformation(context: $TSContext, serviceName: string, functionUrl: string) { | ||
context.print.success(`Successfully added resource ${functionUrl}.`); | ||
context.print.info(""); | ||
context.print.info('Next steps:'); | ||
context.print.info("1. Open https://api.slack.com/apps in your browser."); | ||
context.print.info(`2. Update settings.interactivity.request_url with ${functionUrl} in Slack App Manifest for ${serviceName}.`); | ||
context.print.info(""); | ||
} | ||
|
||
function getFunctionUrlBySerivceName(amplifyMeta: $TSMeta): Record<string, string> { | ||
return Object.entries<Record<string, any>>(amplifyMeta.consolenotification) | ||
.reduce((all, [serviceName, service]) => { | ||
all[serviceName] = service.output.LambdaFunctionUrl; | ||
return all; | ||
}, {} as Record<string, string>); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...plify-slack-nodejs-function-template-provider/resources/lambda/amplifyslackapp/event.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"Records": [ | ||
{ | ||
"EventSource": "aws:sns", | ||
"EventVersion": "1.0", | ||
"EventSubscriptionArn": "arn:aws:sns:ap-northeast-1:123456789012:amplify-appId_dev:3b84ba66-f0a2-4320-87d6-a01f8674974e", | ||
"Sns": { | ||
"Type": "Notification", | ||
"MessageId": "86886283-6134-460c-a0bf-e96404da803d", | ||
"TopicArn": "arn:aws:sns:ap-northeast-1:123456789012:amplify-appId_dev", | ||
"Subject": null, | ||
"Message": "\"Build notification from the AWS Amplify Console for app: https://dev.appId.amplifyapp.com/. Your build status is SUCCEED. Go to https://console.aws.amazon.com/amplify/home?region=ap-northeast-1#appId/dev/1 to view details on your build. \"", | ||
"Timestamp": "2019-10-24T06:33:19.479Z", | ||
"SignatureVersion": "1", | ||
"Signature": "signature", | ||
"SigningCertUrl": "https://sns.ap-northeast-1.amazonaws.com/SimpleNotificationService-xxx.pem", | ||
"UnsubscribeUrl": "https://sns.ap-northeast-1.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:ap-northeast-1:123456789012:amplify-appId_dev:3b84ba66-f0a2-4320-87d6-a01f8674974e", | ||
"MessageAttributes": {} | ||
} | ||
} | ||
] | ||
} |
36 changes: 36 additions & 0 deletions
36
...ify-slack-nodejs-function-template-provider/resources/lambda/amplifyslackapp/index.js.ejs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<%= props.topLevelComment %> | ||
|
||
import { AmplifyConsoleSlackApp } from "amplify-slack-app"; | ||
import { LogLevel } from "@slack/bolt"; | ||
import { SSMClient, GetParametersCommand } from "@aws-sdk/client-ssm"; | ||
|
||
const getSecrets = async (names) => { | ||
const client = new SSMClient(); | ||
const input = { | ||
Names: names, | ||
WithDecryption: true, | ||
}; | ||
const command = new GetParametersCommand(input); | ||
const response = await client.send(command); | ||
return response.Parameters.reduce( | ||
(params, param) => ({ | ||
...params, | ||
[param.Name]: param.Value, | ||
}), | ||
{} | ||
); | ||
}; | ||
|
||
const secrets = await getSecrets([ | ||
process.env.SLACK_SIGNING_SECRET, | ||
process.env.SLACK_BOT_TOKEN, | ||
]); | ||
|
||
const app = new AmplifyConsoleSlackApp({ | ||
signingSecret: secrets[process.env.SLACK_SIGNING_SECRET], | ||
token: secrets[process.env.SLACK_BOT_TOKEN], | ||
defaultChannel: process.env.SLACK_DEFAULT_CHANNEL, | ||
logLevel: LogLevel.DEBUG, | ||
}); | ||
|
||
export const handler = app.createHandler(); |
12 changes: 12 additions & 0 deletions
12
...slack-nodejs-function-template-provider/resources/lambda/amplifyslackapp/package.json.ejs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "<%= props.functionName %>", | ||
"version": "1.0.0", | ||
"description": "Slack App for Amplify Console", | ||
"main": "index.js", | ||
"type": "module", | ||
"license": "Apache-2.0", | ||
"dependencies": { | ||
"@aws-sdk/client-ssm": "^3.150.0", | ||
"amplify-slack-app": "^1.1.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.