fixthestatusquo / proca-server

Proca server, SDKs and services
https://proca.app
5 stars 3 forks source link

Cancel messages for targets #240

Closed 1v4n4 closed 6 months ago

1v4n4 commented 7 months ago

User story: as a campaigner, I want to be able to stop sending emails to a target (for instance if they said they will do what we want or aren't working there anymore)

right now for safety reasons, the api

upsertTargets(
   campaignId: Int!
   replace: Boolean
   targets: [TargetInput!] {
      area: String
      emails: [TargetEmailInput!]
      externalId: String!
      fields: Json
      locale: String
      name: String
   }
): [PrivateTarget]!

has a parameter replace=true mode that tries to remove the targets that were on the server but aren't sent in the targets parameter if and only if there aren't any real (non test) action/message associated with the target

this is good to prevent data loss, however it has proved its limitation and we need to be able to remove targets even if they had messages

We need to be able to "soft delete" a target that has messages, ie:

  1. stop sending new emails to them and
  2. stop sending emails from previous actions that were scheduled to sent but not sent yet

We can either have new api call[s] (eg deleteTarget[s] ) or add an extra param/mode on the upsertTargets (eg. forceDelete) that will soft delete the target AND soft delete the messages/actions. I'd prefer the second option

to soft delete a target, a solution - is to be able to change the target's email status to "canceled". In that case, it will automatically prevents any pending emails/actions to be processed further

We have these email statuses now:

enum EmailStatus {
  "An unused email. (Warning:  Or used, but we do not store the fact that emails are delivered ok)"
  NONE

  "The user has received a DOI on this email and accepted it"
  DOUBLE_OPT_IN

  "This email was used and bounced"
  BOUNCE

  "This email was used and blocked"
  BLOCKED

  "This email was used and marked spam"
  SPAM

  "This email was used and user unsubscribed"
  UNSUB
}

We probably should modify the actions too to explicitly show they will never be processed (processing_status) to be investigated further

1v4n4 commented 7 months ago

@destag

Here are the instructions on how to set up the MTT campaign, I'm not sure how deep you need to go into it at this moment, each of these steps needs further explanations and possibly authorizations (ask for help). The last two are important.

You can use a test campaign "id": 751, "name": "remove_targets_test", "org": { "name": "ftsq", "title": "Fix the Status Quo" }, "title": "Remove targets" and widget "actionpage": 3490, preview page https://widget.proca.app/d/remove_targets_test/ftsq/en/index.html?proca_test (adding?proca_test` at the end of the URL puts the widget in test mode).

What email do you use for proca setup? I think you need to be a part of FTSQ org to be able to access/change this campaign (will send you an invitation)

Steps to create an MTT (mail to target) campaign:

  1. Add a campaign using mutation, proca cli, or the dashboard (I added remove_targets_test under FTSQ organization)

  2. Add MTT settings and letter text to campaign configuration (“config”), our example: { "config": { "component": { "email": { "counter": true, "field": { "message": { "required": true }, "subject": { "required": true } }, "filter": [ "country" ], "listUrl": true, "salutation": false, "selectable": true }, "loader": { "appendLocale": true, "json": true, "url": "https://ep2024_citizen_votepalestine.proca.app/" }, "register": { "actionType": "email", "button": "action.email", "field": { "comment": false, "country": false, "lastname": true, "locality": true, "postcode": { "required": false } } } }, "journey": [ "Email", "Share" ], "layout": { "template": "ep2024.html" }, "locales": { "en": { "common:": { "selectAll": "Select all", "target": { "missing": "Select at least one out of {{total}}" } }, "letter:": { "part-1": "", "part-2": "", "part-3": "", "part-8": "Thank you for your support.\n{{name}}", "subject": "" } } }, "portal": [ "LoaderAsync" ] }, "id": 751, "name": "remove_targets_test", "org": { "name": "ftsq", "title": "Fix the Status Quo" }, "title": "Remove targets" }

  3. Run Snowflake Engine – an app (https://github.com/fixthestatusquo/snowflake_engine) that randomly generates the message from “letter” keys in the "config", and we fetch that message from the widget. Text example uses API from the Vote for Palestine campaign (“url” key in “config”, https://ep2024_citizen_votepalestine.proca.app/)

The last two steps are about target management (same as the issue) it would be important to understand

  1. Generate the targets The details are in proca/docs/targets.md, please ask what is not clear!

The test campaign uses a few ep2024 real targets, 11 from source/ep2024_citizen_votepalestine. They are here https://widget.proca.app/t/remove_targets_test.json

  1. Set the start and end date/time of the MTT The email-sending interval is between these two dates. Time also matters! Emails are sent every day in the time interval between the start time and the end time If we set the start time after the end time, email will never be sent. For example: 2034-03-21T08:21:00Z -> 2034-12-02T18:21:00Z means that emails are evenly spread through 2034-03-21 and 2034-12-02 period and sent only between 08:21:00 and 18:21:00. Test campaign runs far in the future, which should prevent sending real messages, even out of the test mode.

@tttp, please add/change if I'm not making sense.