|
| 1 | +--- |
| 2 | +title: Messages sent to user |
| 3 | +identifier: fetch_messages |
| 4 | +layout: default |
| 5 | +--- |
| 6 | + |
| 7 | +The agreement type `FETCH_MESSAGES` allows a sender to retrieve metadata for |
| 8 | +documents that sender has previously sent to the user, that e.g. can be used to |
| 9 | +present a synthetic inbox to the user. The metadata includes a deep-link the |
| 10 | +user can use to access the document in Digipost. |
| 11 | + |
| 12 | + |
| 13 | +### Create, read, update and delete agreement |
| 14 | + |
| 15 | +```java |
| 16 | +final SenderId senderId = SenderId.of(1234L); |
| 17 | +final UserId userId = UserId.of("01017012345"); |
| 18 | + |
| 19 | +//CreateAgreement |
| 20 | +client.createOrReplaceAgreement(senderId, Agreement.createAgreement(userId, AgreementType.FETCH_MESSAGES)); |
| 21 | + |
| 22 | +//GetAgreement |
| 23 | +final GetAgreementResult agreement = client.getAgreement(senderId, AgreementType.FETCH_MESSAGES, userId); |
| 24 | + |
| 25 | +//UpdateAgreement |
| 26 | +client.createOrReplaceAgreement(senderId, Agreement.createAgreement(userId, AgreementType.FETCH_MESSAGES)); |
| 27 | + |
| 28 | +//DeleteAgreement |
| 29 | +client.deleteAgreement(senderId, AgreementType.FETCH_MESSAGES, userId); |
| 30 | +``` |
| 31 | + |
| 32 | +### Get and verify agreement |
| 33 | + |
| 34 | +```java |
| 35 | +final SenderId senderId = SenderId.of(1234L); |
| 36 | +final UserId userId = UserId.of("01017012345"); |
| 37 | + |
| 38 | +final GetAgreementResult agreementResult = client.getAgreement(senderId, AgreementType.FETCH_MESSAGES, userId); |
| 39 | +if (agreementResult.isSuccess()) { |
| 40 | + final Agreement agreement = agreementResult.getAgreement(); |
| 41 | +} else { |
| 42 | + switch (agreementResult.getFailedReason()) { |
| 43 | + case UNKNOWN_USER: //User does not have a Digipost account |
| 44 | + case NO_AGREEMENT: //No agreement exists for user |
| 45 | + } |
| 46 | +} |
| 47 | +``` |
| 48 | + |
| 49 | +### Get documents |
| 50 | + |
| 51 | +```java |
| 52 | +final SenderId senderId = SenderId.of(1234L); |
| 53 | +final UserId userId = UserId.of("01017012345"); |
| 54 | + |
| 55 | +final List<Document> previouslyDeliveredDocs = client.getDocuments(senderId, AgreementType.FETCH_MESSAGES, |
| 56 | + userId, GetDocumentsQuery.empty()); |
| 57 | + |
| 58 | +final ZoneId OSLO_ZONE = ZoneId.of("Europe/Oslo"); |
| 59 | +final List<Document> withinTimeWindow = client.getDocuments(senderId, AgreementType.FETCH_MESSAGES, userId, |
| 60 | + GetDocumentsQuery.builder() |
| 61 | + .deliveryTimeFrom(ZonedDateTime.of(2020, 1, 1, 0, 0, 0, 0, OSLO_ZONE)) |
| 62 | + .deliveryTimeTo(ZonedDateTime.now(OSLO_ZONE)) |
| 63 | + .build()); |
| 64 | +``` |
0 commit comments