GithubHelp home page GithubHelp logo

msupply-foundation / notify Goto Github PK

View Code? Open in Web Editor NEW
0.0 0.0 1.0 3.02 MB

"Notify" a multi channel notification scheduling tool

License: GNU Affero General Public License v3.0

Rust 53.63% Shell 0.24% HTML 1.76% JavaScript 0.36% TypeScript 43.92% Batchfile 0.09%

notify's People

Contributors

andreievg avatar dependabot[bot] avatar ethanmcq-tmf avatar jmbrunskill avatar lache-melvin avatar mai21 avatar mark-prins avatar ravisussol avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

zzuzka

notify's Issues

Ability to query recipients from Datasource

Is your feature request related to a problem? Please describe

As a configurator, I want to be able to get a list of recipients via an SQL query.

Describe the solution you'd like

This feature should be implemented as a Proof of concept, and something we can improve on an extend in future.

Validate NotificationConfig configuration_data JSON on create/update

Is your feature request related to a problem? Please describe

The diesel Json type is only available when the postgres feature is enabled, but our repository db uses SQLite. So, we're storing the configuration_data as a string (and will parse the JSON later when we use it.) However, we don't currently have any validation on that JSON string when it comes in (not even that it does parse to valid JSON!) We probably should.

For as long as we can't store the JSON as the Json type, we probably should at least check the string is parsable. We could also have a parse method available by the different plugins, to validate that the configuration data is in the expected format for a notification of that kind?

"Borrow" Frontend code

Take the frontend code from HSH and/or open-mSupply and commit a stripped back version.

Things we don't need:

  • Organisation based logins (the system will all be the one organisation)
  • Tenders/Quotes/Manufacturers/Organisations

Things we do need:

  • Logins
  • Layout/structure
  • User account

Create Recipient Lists

Is your feature request related to a problem? Please describe

We need a way to configure reusable email lists/Telegram groups/perhaps a mix of both (?) which can then be referenced as the destination(s) when configuring a new notification.

Describe the solution you'd like

Could look a lot like HSH Supplier lists.

  • A list of emails, potentially also with names so we can address the email to someone.
  • An input for Telegram chat IDs. This needs some R&D:
    • If we're given the chat ID can we then get the group name (more user friendly... if not we should probably let them input that themselves?)
    • Do we need instructions to walk the user through inviting our bot to a new group?
    • How can we confirm our bot has been invited to that group?
      • Can we store the chat ID's we've been invited to and show those?

Tutorial: How to add a filter

Is your feature request related to a problem? Please describe

  • Mapping to graphql filter type
  • Adding a test case for the filter

Add description field to audit logs

Is your feature request related to a problem? Please describe

Sometimes we there isn't enough context/info from just the log type and the included id. An optional description would be a helpful first step in fleshing out our audit logs, especially for logs like RecipientAddedToList (include recipient name/id in the description)

Remove sort input being an array

Is your feature request related to a problem? Please describe

We currently only support the first item of the sort input array anyway, let's get rid of the array and just accept one sort param. We're unlikely to need more complex sorting for this app anyway.

Error loading configuration view

Is your feature request related to a problem? Please describe

Some view like this when opening a notification config where the configuration data is unable to be parsed. Currently the form just renders empty, and there is a little error popup.

Could also disable the ok button.
image

Describe the solution you'd like

Describe alternatives you've considered

Additional context

Telegram crate/service

Is your feature request related to a problem? Please describe

Build a interface for working with telegram.

Describe the solution you'd like

  • Should allow some kind of code based interface for sending telegram alerts
  • Could provide a graphql interface for testing a telegram message
  • Could/Should provide a list of chatids based on querying data from telegram API.

Create recipients page

Is your feature request related to a problem? Please describe

The UI needs a page where we list all recipients, and where you could update them.

Allow '&' in recipient list name

Is your feature request related to a problem? Please describe

Kapture 2023-09-07 at 09 09 16

Describe the solution you'd like

I think and & symbol should allowed when setting up lists.
For example you might want to include two stores "Store A & Store B" for example.

Describe alternatives you've considered

Additional context

Can't invite users

Describe the bug

image

To Reproduce

Steps to reproduce the behaviour:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behaviour

Additional context

I think this is because we don't have any available roles to select in the modal

Method to read data from mSupply Postgres

Is your feature request related to a problem? Please describe

We need to read data from postgres for cold chain. This might just be a special repository/repository type that allows for other queries and connections?

Describe the solution you'd like

When would you like it?

Describe alternatives you've considered

Additional context

Backend to manage NotificationConfig

Is your feature request related to a problem? Please describe

When setting up a notification we want some common backend components that we can use to save the configuration.
This might be more complex for some plugins in future, but this will be a good starting point

Describe the solution you'd like

A table something like this...

NOTIFICATION_CONFIG {
    TEXT id PK "UNIQUE NOT NULL"
    TEXT title "NOT NULL"
    TEXT plugin_type "NOT NULL (COLD_CHAIN/ETC)"
    TEXT recipient_ids "(JSON?)"
    TEXT recipient_list_ids "(JSON?)"
    TEXT configuration_data "NOT NULL (JSON)"
}

Code to create & update configs

  • graphql
  • service
  • repository

Querying can be a separate issue...

Refactor service context so we don't need circular dependancies

Is your feature request related to a problem? Please describe

Currently service provider is used from within service context. This feature isn't really useful and create dependancy problems.

Describe the solution you'd like

When would you like it?

Describe alternatives you've considered

Additional context

Add recipient/list IDs to notification config

Is your feature request related to a problem? Please describe

Currently, we are storing the recipient ids and recipient list ids for notification configs in the configuration_data. However, as every notification config will have these fields, it should be on the base NotificationConfig.

Describe the solution you'd like

These should probably be two new join tables (notification_config_recipient & notification_config_recipient_list). They could then be added to the NotificationConfigNode via loaders in the graphql layer for the frontend.

Describe alternatives you've considered

Originally we thought to simply have recipientIds and recipientListIds as fields on the NotificationConfig, but this is a bit brittle (i.e. if a recipient is deleted, or what if we want to see that the notifications a recipient is subscribed to?) The join seems more robust/flexible.

Additional context

Add the ability to add new recipients from the recipient list view

Is your feature request related to a problem? Please describe

If you are editing a recipient list, it would be nice to be able to quickly create a new recipient if the one you are looking for doesn't already exist...

Describe the solution you'd like

On the Recipient list view...

Either

  • a create new recipient button
    image

  • or when searching if you don't find anything offer to create new?

image

Describe alternatives you've considered

Additional context

Send test message to Telegram Recipients

Is your feature request related to a problem? Please describe

Add ability to send a test telegram message to a telegram recipient.

Describe the solution you'd like

Some button on the recipient modal?

Test method for Scheduled Reports

Is your feature request related to a problem? Please describe

Right now it's really hard to test out a scheduled report to see if it works, it would be great if there's a way to

Describe the solution you'd like

Add a new Test button similar to the test query button on the Notification Query Page.

It should return a view with information such as.

  • How the template would render, or the error received trying to render the template
  • List of recipients that would be notified
  • Any other errors that can occur would be available

Describe alternatives you've considered

  • A run this now button would be very useful
  • A veiw allowing you to see all notifications, espeically any failed ones with their errors would be useful

Additional context

Add Telegram botname to Admin Screen

Is your feature request related to a problem? Please describe

It would be nice to easily find the configured telegram bot name in the UI

Describe the solution you'd like

Something like this...

image

GenericError Cleanup

Is your feature request related to a problem? Please describe

Having a consistent approach to dealing with service errors, especially rare ones that may require different user actions is important.

TODO Link to Code Review comments once it's written...

Describe the solution you'd like

Replace GenericError with InternalError or BadUserInput as per usage.

Describe alternatives you've considered

Additional context

KDD - Database Technology/approach

Assume will do postgres to align with mSupply/grafana databases, but could still have sqlite a long side, this is what the grafana plugin does already?

Do we still need sqlite for testing (I assume Yes)

Do we have a separate connection string/setting for configuring postgres internal db vs ones it connects too to monitor?

Implement email notification sending

Is your feature request related to a problem? Please describe

Describe the solution you'd like

Describe alternatives you've considered

Additional context

Enter key doesn't select checkboxes

Describe the bug

You can use the tab key to tab through the Cold Chain notification toggle fields, but the enter key doesn't select them.
Screenshot 2023-08-24 at 3 43 07 PM

To Reproduce

Steps to reproduce the behaviour:

  1. Go to 'Notifications'
  2. Click on 'New Notification'
  3. Use the tab key to tab to a checkbox
  4. Press enter
  5. The checkbox doesn't select

Expected behaviour

The enter key selects/deselects the highlighted checkbox

Additional context

"Borrow" backend code

Take the backend code from HSH and/or open-mSupply and commit a stripped back version.

Things we don't need:

  • Tenders/Quotes/Manufacturers/Organisations

Things we do need:

  • Logins
  • Layout/structure
  • User account
  • Emails? Maybe gets a refactor to make it more generic
  • Email sending process
  • Basic Uploads/Temporary downloads?

Things I'd like to change:

  • Permissions checks should be in the service layer (graphql can check authentication, authorisation should be separate in the the service layer

Remove db feature flags from repository crate

Is your feature request related to a problem? Please describe

As discussed with Andrei, having feature flags that aren't being used causes confusion to devs.
We should remove them. If we need to support postgres and sqlite in the future again we can always re-instate them.

Watch for tera template updates/additions

Is your feature request related to a problem? Please describe

Tera templates can be reloaded like this:
tera.full_reload()?;
https://tera.netlify.app/docs/#reloading

Describe the solution you'd like

Would be awesome if we could either a trigger a reload from the UI, or automatically watch for changes to templates.

Describe alternatives you've considered

  • Restart the server to pick up new templates
  • Add templates via the UI somehow?

Additional context

Ideally would do some kind of validation and only reload it the templates actually work???

Implement soft delete on recipients

Describe the bug

You cannot delete a recipient if they are a part of a recipient list.

To Reproduce

Steps to reproduce the behaviour:

  1. Add a recipient to a recipient list
  2. Try to delete the recipient
  3. See foreing key constraint violation error

Expected behaviour

No error - deleting a recipient should be possible, and they should no longer appear in the recipient list(s).

Additional context

Either soft delete recipients, and then add an additional filter on recipient list members that the recipient isn't flagged as deleted, or delete all recipient list members for that recipient id - maybe one is better than the other for logging/transparency/etc?

Read datasource configuration from config files

Is your feature request related to a problem? Please describe

Need a method for configuring datasources for notify to use.

Describe the solution you'd like

Probably part of the main local.yaml

Describe alternatives you've considered

Cold chain telegram alert

Is your feature request related to a problem? Please describe

We want to display a nice alert in telegram when there is a temperature breach.

Describe the solution you'd like

For this issue, we want to.

  • Create a test case that passes example data to a template to render the following alert
  • Create a test case the sends the example alert to the test Telegram Channel (via environment variable)

High temperature alert!

Facility: Store A
Location: Fridge 1
Sensor: E5:4G:D4:6D:A4

Date: 17 Jul 2023
Time: 17:04

Temperature: 10° C

//// ~ insert cute graph here ~ ////

Small link to dashboard (hyperlinked so not massive wall of text)

Describe alternatives you've considered

  • Should the template be completely replaceable or part of the coldchain crate?
  • Creating a the graph is out of scope for now!

Additional context

In future we'll have other kinds of alerts and data, so we should consider this while coding but hard code if fine for now.

Get all recipient ids for a notification config

Is your feature request related to a problem? Please describe

There is a many to many relationship between both NotificationConfig and Recipient, and NotificationConfig and RecipientList. However, when it comes to sending the notification, we don't really care about the recipient lists, we just want to know who to send the notification to.

Describe the solution you'd like

Would be great to have some kind of get_all_recipients_for_notification_config in the service layer, that resolves all the recipient ids for any selected recipient lists, and joins these will the selected recipient ids.

Describe alternatives you've considered

Additional context

It's probably fine just to return all the ids? And let the notification sending code query any extra required information?

Cold chain alerts form

Is your feature request related to a problem? Please describe

A cold chain alert should be possible to setup with a simple form.

Each alert will apply to a group of stores, locations, or sensors.
The user should be able to select a store and all the locations and sensor underneath would be automatically included.
(similar for a location)

Each notification will apply to one group of stores/sensors/etc and any notification groups included will be notified with the same data.

Note: If we want separate alerts for different stores, we'll need to setup multiple notifications/alerts.

Describe the solution you'd like

image

Ideally this would be configured with a JSONForm so conceptually it's generic.
however if we have to hard code so be it.

Managing how to actually store and process the data will be a separate issue.

Telegram bot doesn't correctly handle direct messages

Describe the bug

[2023-08-10T23:44:23Z ERROR telegram::service] Error parsing update: Error("missing field title", line: 0, column: 0) update: Object({"message": Object({"chat": Object({"first_name": String("James"), "id": Number(5068627745), "last_name": String("Brunskill"), "type": String("private")}), "date": Number(1691711063), "entities": Array([Object({"length": Number(6), "offset": Number(0), "type": String("bot_command")})]), "from": Object({"first_name": String("James"), "id": Number(5068627745), "is_bot": Bool(false), "language_code": String("en"), "last_name": String("Brunskill")}), "message_id": Number(77), "text": String("/start")}), "update_id": Number(794348098)})

To Reproduce

Steps to reproduce the behaviour:

  1. Chat with bot
  2. Not chat_id recorded in the db

Expected behaviour

Chat Id should be recorded but with users name?

Additional context

In PR #20

POC - Scheduled Report Configurations

Is your feature request related to a problem? Please describe

Create a mock up for scheduled report config.

Describe the solution you'd like

Describe alternatives you've considered

Additional context

Initial DB Design

Task

Create a mermaid diagram with a database structure in the docs folder.

Acceptance Criteria

  • Provides a basis for starting the application development, obviously will have some changes later

Soft delete recipient lists and notification configs.

Describe the bug

Given there is a many-many join table for the relationships between notification configs and their recipients/recipients lists, you currently get a foreign key constraint violation if you try to delete a notification config while has recipients, or a recipient list while it is associated with a notification config.

Recipients have soft deleted implemented on them, we also need it on RecipientLists and NotificationConfigs.

To Reproduce

Steps to reproduce the behaviour:

Add a recipient list to a notification config.

  • Try to delete the notification config (see error)
  • Try to delete the recipient list (see error)

Expected behaviour

No errors, delete (softly) the entities

Additional context

datasource tests fail without ENV

Describe the bug

running 3 tests
test tests::test_select_with_with ... FAILED
test tests::test_invalid_query ... FAILED
test tests::test_simple_select ... FAILED

failures:

---- tests::test_select_with_with stdout ----
thread 'tests::test_select_with_with' panicked at 'the DATABASE_URL environment variable must be set: NotPresent', datasource/src/lib.rs:66:38

---- tests::test_invalid_query stdout ----
thread 'tests::test_invalid_query' panicked at 'the DATABASE_URL environment variable must be set: NotPresent', datasource/src/lib.rs:87:38
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace

---- tests::test_simple_select stdout ----
thread 'tests::test_simple_select' panicked at 'the DATABASE_URL environment variable must be set: NotPresent', datasource/src/lib.rs:43:38

To Reproduce

Steps to reproduce the behaviour:

  1. Run tests without

Expected behaviour

Should be able to run default tests without errors. Maybe a default postgres config, feature flag or similar?

Additional context

backoff for notification retries

Is your feature request related to a problem? Please describe

If a notification can't be sent with a temporary error, we should retry sending, but should wait longer between each attempt.

Describe the solution you'd like

Suggest something like

  1. Try to send immediately
  2. Wait 1 Minute try again
  3. Wait 15 Minutes try again
  4. Wait 1 Hour try again

Describe alternatives you've considered

We could have more attempts and/or change the logic abit, I'm not too precious about it.
I think anything that can't be sent say with in 12 hours definitely shouldn't be sent, but maybe we should try again within 2-4 hours?

Additional context

Recipient List Sql Query endpoint

Is your feature request related to a problem? Please describe

When setting up a recipient list with an SQL Query, you want to be able to test that your query works.
We also want to be able to use the results of a query when creating a notification.

Describe the solution you'd like

We want graphql request that returns a list of Recipient Rows based on an SQL query (in future possible a template and params?)

Server should throw an error if the query results can't be mapped to a list of recipients
Hopefully error type can contain the json received from the DB so we can investigate/understand what's not matching, and/or good error messages.

Describe alternatives you've considered

Keep what we have in PR #97

telegramBotName query returns error as success data

Describe the bug

Running a query for the bot name, query results should be in the following format:

{
  "status":"success",
  "isLoading":false,
  "isSuccess":true, // if true, error is null and data populated
  "isError":false,  // if true, data is null and error populated
  "data":"some-botname",
  "error": null,
  ...
}

However, if there is an error getting the botname, it still "succeeds" and sets the error message as the data.

{
  "status":"success",
  "isLoading":false,
  "isSuccess":true,
  "isError":false,
  "data":"Unable to get botname : Temporary(TimedOut(\"error sending request for url (https://api.telegram.org/bot6374528256:AAGgjZaS_6qnrtZFDGRtu6fFiOsaEiClNSI/getMyName): operation timed out\"))",
  // or "data": "Telegram service not configured"
  "error": null,
  ...
}

To Reproduce

Steps to reproduce the behaviour:

  1. Make telegram inaccessible somehow (remove bot token from local.yaml, disconnect internet connection...)
  2. Query for telegramBotName
  3. Receive the error message as the response data

Expected behaviour

botName to be null, with an explanatory error message as to why it is unavailable. We aren't always wanting to throw (bot may not be configured, that is okay)... maybe the success return type could be something like:

{
  name: String | null
  reason: String | null
}

If there is an actual error, it should come through as an error though?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.