Messaging¶
MessagingAccessor on Dhis2Client.messaging — DHIS2 internal messaging via /api/messageConversations. Pairs with the files plugin for MESSAGE_ATTACHMENT fileResources: upload via client.files.upload_file_resource(..., domain="MESSAGE_ATTACHMENT"), then reference the UID in send / reply.
messaging
¶
DHIS2 internal messaging — /api/messageConversations.
Natural pairing with the files plugin: a MESSAGE_ATTACHMENT-domain
fileResource uploaded via client.files.upload_file_resource(...) returns
a UID that references directly from a message. The same fileResource can
be read back via client.files.download_file_resource(uid) once the
conversation recipient has access.
Covers:
- Inbox reads (
list_conversations/get_conversation) - Conversation creation + reply (
send/reply) - Read-state toggle (
mark_read/mark_unread) + delete - Ticket-workflow fields (
set_priority/set_status/assign/unassign). These work on PRIVATE conversations too — DHIS2 stores the fields regardless ofmessageType; they're most meaningful whenmessageType=TICKET.
Classes¶
MessageConversation
¶
Bases: BaseModel
OpenAPI schema MessageConversation.
Source code in packages/dhis2w-client/src/dhis2w_client/generated/v42/oas/message_conversation.py
Recipient
¶
Bases: BaseModel
One addressee of an outgoing message — reference to a user, user group, or organisation unit.
Messages accept three overlapping recipient lists (users, userGroups,
organisationUnits); every kind is an {id} reference on the wire.
Recipient is a thin domain name over that — kind names where DHIS2
delivers the message, uid is the referenced entity.
Source code in packages/dhis2w-client/src/dhis2w_client/messaging.py
MessagingAccessor
¶
Dhis2Client.messaging — conversation list + send + reply + mark-read.
Returns typed MessageConversation from the OAS schema. For attachments,
upload via client.files.upload_file_resource(..., domain='MESSAGE_ATTACHMENT')
first, then pass the returned UID to send / reply via attachments.
Source code in packages/dhis2w-client/src/dhis2w_client/messaging.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 | |
Functions¶
__init__(client)
¶
list_conversations(*, filter=None, page=None, page_size=None)
async
¶
List conversations the authenticated user is part of.
filter accepts DHIS2's standard property:operator:value DSL
(e.g. "read:eq:false" for unread-only). page is 1-indexed;
DHIS2 defaults pageSize to 50.
Source code in packages/dhis2w-client/src/dhis2w_client/messaging.py
get_conversation(uid)
async
¶
Fetch one conversation with its full message thread (/api/messageConversations/{uid}).
Explicit fields= selector — DHIS2's default selector returns only
messages[id], so the text + sender + created timestamp have to be
asked for. This fetches enough to render a readable thread without
bringing down translations / sharing / attribute values.
Source code in packages/dhis2w-client/src/dhis2w_client/messaging.py
send(*, subject, text, users=None, user_groups=None, organisation_units=None, attachments=None)
async
¶
Create a new conversation + first message; returns the new conversation.
At least one of users / user_groups / organisation_units must
be non-empty — DHIS2 silently drops messages with no recipients.
Each value is a UID. attachments is a list of fileResource UIDs
previously uploaded with domain=MESSAGE_ATTACHMENT.
The returned MessageConversation is freshly fetched — the
create endpoint returns just the status envelope, not the new
UID (see BUGS.md #17). The UID is extracted from the 201
Location header; this method GETs the conversation back so the
caller receives a typed object instead of parsing a URL.
Source code in packages/dhis2w-client/src/dhis2w_client/messaging.py
reply(uid, *, text)
async
¶
Reply to an existing conversation (POST /api/messageConversations/{uid}).
DHIS2's reply endpoint takes text/plain body — not JSON — and
stores the raw bytes as the message text. JSON objects get
stringified verbatim. Attachments + the internal-note flag only
work on the initial send(); to attach a file after a conversation
already exists, start a new conversation (or use
/api/messageConversations/{uid}/attachments via post_raw
directly if your DHIS2 build supports it — not wired here).
Source code in packages/dhis2w-client/src/dhis2w_client/messaging.py
mark_read(uids)
async
¶
Flip one or many conversations to read (POST /api/messageConversations/read).
DHIS2's bulk endpoint takes an array body of UIDs. A single string input is wrapped for convenience.
Source code in packages/dhis2w-client/src/dhis2w_client/messaging.py
mark_unread(uids)
async
¶
Flip one or many conversations to unread (POST /api/messageConversations/unread).
Source code in packages/dhis2w-client/src/dhis2w_client/messaging.py
delete_conversation(uid)
async
¶
Delete a conversation. DHIS2 soft-deletes for the calling user — other participants still see it.
Source code in packages/dhis2w-client/src/dhis2w_client/messaging.py
set_priority(uid, priority)
async
¶
Set the ticket-workflow priority on a conversation.
Accepts "NONE" / "LOW" / "MEDIUM" / "HIGH" (matching the
MessageConversationPriority OAS enum). DHIS2 accepts this call on
any message type — most useful on TICKET-type conversations but
stores on PRIVATE threads too.
Source code in packages/dhis2w-client/src/dhis2w_client/messaging.py
set_status(uid, status)
async
¶
Set the ticket-workflow status on a conversation.
Accepts "NONE" / "OPEN" / "PENDING" / "INVALID" / "SOLVED"
(matching the MessageConversationStatus OAS enum).
Source code in packages/dhis2w-client/src/dhis2w_client/messaging.py
assign(uid, user_uid)
async
¶
Assign a conversation to a user (ticket workflows).
Source code in packages/dhis2w-client/src/dhis2w_client/messaging.py
unassign(uid)
async
¶
Remove the assignee from a conversation.