Skip to content

hmrc/secure-message

Repository files navigation

secure-message

Micro-service responsible for providing a secure communication channel between HMRC and it's customers.

Run the project locally

Ensure you have service-manager python environment setup:

source ../servicemanager/bin/activate

sm2 --start DC_TWSM_ALL

sm2 --stop SECURE_MESSAGE

sbt "run 9051 -Dplay.http.router=testOnlyDoNotUseInAppConf.Routes"

Run the tests and sbt fmt before raising a PR

Ensure you have service-manager python environment setup:

source ../servicemanager/bin/activate

Format:

sbt fmt

Then run the tests and coverage report:

sbt clean coverage test coverageReport

If your build fails due to poor test coverage, DO NOT lower the test coverage threshold, instead inspect the generated report located here on your local repo: /target/scala-2.12/scoverage-report/index.html

Then run the integration tests:

NOTE: for integration tests to work, make sure to have all the external services required. You can use the following commands to start/stop the required services.

sm2 --start DC_SECURE_MESSAGE_IT sm2 --start DC_SECURE_MESSAGE_IT

sbt it:test

Sample data

{
    "_id" : ObjectId("6021481d59f23de1fe8389db"),
    "client" : "CDCM",
    "conversationId" : "D-80542-20201120",
    "status" : "open",
    "subject" : "D-80542-20201120",
    "language" : "en",
    "participants" : [ 
        {
            "id" : 1,
            "participantType" : "system",
            "identifier" : {
                "name" : "CDCM",
                "value" : "D-80542-20201120"
            },
            "name" : "CDS Exports Team"
        }, 
        {
            "id" : 2,
            "participantType" : "customer",
            "identifier" : {
                "name" : "EORINumber",
                "value" : "GB1234567890",
                "enrolment" : "HMRC-CUS-ORG"
            }
        }
    ],
    "messages" : [ 
        {
            "senderId" : 1,
            "created" : "2021-02-08T14:18:05.986+0000",
            "readBy" : [],
            "content" : "QmxhaCBibGFoIGJsYWg="
        }
    ]
}

For more examples of resources which can be inserted in your local mongo database secure-message, collection conversation, can be found here

API

Path Supported Methods Description
/v4/message POST Add a new v4 message More...
/messages GET List of messages for user More...
/messages/:encodedId GET Get message by id More...
/messages/:id/content GET **** Get message content by id More...
/messages/:id/read-time POST Sets the time a given message was read More...
/message/system/:id/send-alert GET Returns true if the message identified in the request has not been read, More...

Admin API

Path Supported Methods Description
/admin/message/brake/gmc/batches GET Pulls the message batches which are in deferred status
/admin/message/brake/accept POST Accepts the message in message brake to be delivered
/admin/message/brake/reject POST Rejects the message in message brake to be delivered
/admin/message/brake/random POST Pulls the message with deferred status waiting to be delivered

Endpoints

POST /v4/messages

Create a new v4 message. This is for messages that contain html content in the body.

An example message creation request:

{
  "externalRef": {
    "id": "abcd1234",
    "source": "mdtp"
  },
  "recipient": {
    "regime": "sdil",
    "taxIdentifier": {
      "name": "HMRC-OBTDS-ORG",
      "value": "XZSD00000100024"
    },
    "name": {
      "line1": "Line1",
      "line2": "Line2",
      "line3": "Line3"
    },
    "email": "[email protected]"
  },
  "tags": {
    "notificationType": "Direct Debit"
  },
  "alertDetails": {
    "data": {
      "key1": "value 1",
      "key2": "value2"
    }
  },
  "details": {
    "formId": "SA300",
    "issueDate": "2017-02-13",
    "batchId": "1234567",
    "sourceData": "<base64 encoded source data>",
    "properties": [
      {
        "property": {
          "name": "printedVariant",
          "value": "false"
        }
      }
    ]
  },
  "content": [
    {
      "lang": "en",
      "subject": "Reminder to file a Self Assessment return",
      "body": "Message content - 4254101384174917141"
    },
    {
      "lang": "cy",
      "subject": "Nodyn atgoffa i ffeilio ffurflen Hunanasesiad",
      "body": "Cynnwys - 4254101384174917141"
    }
  ],
  "messageType": "sdAlertMessage",
  "validFrom": "2020-05-04",
  "alertQueue": "DEFAULT"
}

The full schema for this can be found SchemaV4

Responds with status code:

  • 201 if the message is created successfully
  • 400 (Bad Request) if the body is not as per the above definition
  • 400 (Bad Request) if the tax identifier is not supported
  • 409 (Conflict) if the message hash is a duplicate of an existing message

GET /messages

List of messages metadata for the user. Accepts optional parameters:

Name Description
enrolmentKey User's enrolment key
enrolment Customer enrolment
messageFilter Filter with taxIdentifiers & regimes
language For English or Welsh messages

Example response:

[
  {
    "messageType": "letter",
    "id": "bGV0dGVyLzYwOWE1YmQ1MDEwMDAwNmMxODAwMjcyZA==",
    "subject": "Test have subjects11",
    "issueDate": "2021-04-26T00:00:00.000+0000",
    "senderName": "HMRC",
    "unreadMessages": false,
    "count": 1
  }
]

GET /messages/:encodedId

Returns message by id.

Example response for message that has been read:

{
  "id": "57bac7e90b0000490000b7cf",
  "subject": "Test subject",
  "body": {
    "type": "print-suppression-notification",
    "form": "SA251",
    "suppressedAt": "2016-08-22",
    "detailsId": "C0123456781234568"
  },
  "contentParameters": {
    "data": {
      "templateData1": "data1",
      "templateData2": "data2"
    },
    "templateId": "testAlertTemplate"
  },
  "validFrom": "2016-08-22",
  "readTime": "2014-05-02T17:17:45.618Z",
  "sentInError": false,
  "renderUrl": {
    "service": "sa-message-renderer",
    "url": "/message/url"
  }
}

Example response for message that is unread:

{
  "id": "57bac7e90b0000490000b7cf",
  "subject": "Test subject",
  "body": {
    "type": "print-suppression-notification",
    "form": "SA251",
    "suppressedAt": "2016-08-22",
    "detailsId": "C0123456781234568"
  },
  "contentParameters": {
    "data": {
      "templateData1": "data1",
      "templateData2": "data2"
    },
    "templateId": "testAlertTemplate"
  },
  "validFrom": "2016-08-22",
  "markAsReadUrl": {
    "service": "secure-message",
    "url": "secure-messaging/messages/57bac7e90b0000490000b7cf/read-time"
  },
  "renderUrl": {
    "service": "sa-message-renderer",
    "url": "/message/url"
  },
  "sentInError": false
}

POST /messages/:id/read-time

Sets the time a given message was read. This operation is idempotent.

Responds with status code:

  • 200 if the message read time is updated with the current request or has already been set.
  • 404 if a message with the provided id does not exist for the tax ids inferred from the request.

GET /message/system/:id/send-alert

Returns true if the message identified in the request has not been read, false otherwise.

Example response:

{
  "sendAlert": true
}

Responds with status code:

  • 200 if a valid message id is provided
  • 400 if a malformed message id is specified by the URI
  • 404 if a message with the specified message id does not exist

Admin Endpoints

GET /admin/message/brake/gmc/batches

Pulls the message batches which are in deferred status

Example response:

{
  "batchId": "1234567",
  "formId": "SA316",
  "issueDate": "2017-03-16",
  "templateId": "testAlert",
  "count": 1
}

POST /admin/message/brake/accept

Accepts the message in message brake to be delivered

Example request:

{
  "batchId": "1234567",
  "formId": "SA316",
  "issueDate": "2017-03-16",
  "templateId": "testAlert",
  "reasonText": "reason to accept"
}

Responds with status code:

  • 200 if a valid message is accepted
  • 404 if a message with the specified details does not exist

POST /admin/message/brake/reject

Rejects the message in message brake waiting to be delivered

Example request:

{
  "batchId": "1234567",
  "formId": "SA316",
  "issueDate": "2017-03-16",
  "templateId": "testAlert",
  "reasonText": "reason to reject"
}

Responds with status code:

  • 200 if a valid message is rejected
  • 404 if a message with the specified details does not exist

POST /admin/message/brake/random

Pulls the message with deferred status waiting to be delivered

Example request:

{
  "batchId": "1234567",
  "formId": "SA316",
  "issueDate": "2017-03-16",
  "templateId": "testAlert"
}

Example response:

{
  "subject": "Reminder to file a Self Assessment return",
  "welshSubject": "Nodyn atgoffa i ffeilio ffurflen Hunanasesiad",
  "content": "TWVzc2FnZSBjb250ZW50IC0gNDI1NDEwMTM4NDE3NDkxNzE0MQ==",
  "welshContent": "Q3lubnd5cyAtIDQyNTQxMDEzODQxNzQ5MTcxNDE=",
  "externalRefId": "abcd1234",
  "messageType": "sdAlertMessage",
  "issueDate": "2020-05-04",
  "taxIdentifierName": "HMRC-OBTDS-ORG"
}

License

This code is open source software licensed under the Apache 2.0 License.