1.0.10 • Published 2 years ago
@smarterservices/smarter-notifications v1.0.10
Smarter Notifications
Universal package for smarter services apps that will take basic information for notifications such as recipient, notification type, content, etc and fill in the content for the requested notification, then send to an SQS queue to be processed by a lambda function.
This package uses promises (AKA promise/callback hell) versus async/await to remain compatible with the older API projects. If those are updated this should be as well.
Installation
- Setup SSH keys locally following this
npm install ssh://bitbucket.org:smarterservices/smarternotifications.git --save
Example Data for notification
const smarterNotifications = require('smarternotifications');
const notification = {
event: 'test',
accounts: [
{
type: 'appInstall',
id: 'AIf6cbc9874d1f452ab8642723041f6a5f',
recipients: [
{
recipientSid: 'US1aa46e239d9745fcb476e67aba54d308',
type: 'email',
value: 'ryan.wise@smarterservices.com'
}
]
}
],
contentData: {
message: 'ride wheelies to escape the feelies'
}
};
smarterNotifications.sendNotification(notification);
Create Notification CLI Tool
- There is a CLI tool that will prompt you with questions in order to create the records for a new notification.
- Usage
- Rename the file .env.example to .env and put the proper token for ENVKEY
- Then run
npm run create
This will start to prompt you with the following questions:
- ? Notification Name:
- ? Notification Description:
- ? Filter Notification to Single Install?
- ? Delivery Type:
- ? File that contains contentTemplate and Schema:
- ? Enabled by default?
Prompt with example values:
- ? Notification Name: Test Notification
- ? Notification Description: Test Notification Description
- ? Filter Notification to Single Install? No
- ? Delivery Type: Email
- ? File that contains contentTemplate and Schema: ~/repos/smarter-services/smarternotifications/example/notification.json
- ? Enabled by default? Yes
*Note - The Notification Name will be made lower cased and spaces replaced by hyphens used for the event
See example schema in the example folder The notification.json:
{
// Schema is the key values pair that can be replaced in the body or subject templates
"schema": {
"test": "string"
},
// The content template can have a body and subject that will be used for email types and can use
// handlebar type replacements that match the keys in the schema
// SMS types will on use the body
"contentTemplate": {"body": "Test value: {{test}}", "subject": "Subject test value: {{value}}"}
}
Improvements to be made
- Remove dependency on HerokuConnect
- We use a home grown sequelize-middleware package instead of the normal one (that took a while to figure out) That has specific dependencies on herokuConnect.
- Use Sequelize appropriately
- Our app's don't use sequelize properly and that should be changed soon
Required version weirdness
- pg dependency needs to be version 7.4.3
- It will throw a self signed ssl cert error if not
- sequelize dependency needs to be version ^5.21.2
- It will complain that the dialect hasn't been set if not