Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion answer_rocket/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def send_email(
subject: str,
body: str,
user_ids: Optional[List[UUID]] = None,
group_ids: Optional[List[UUID]] = None
group_ids: Optional[List[UUID]] = None,
attachments: Optional[List[dict]] = None
) -> EmailSendResponse:
"""
Send an email to specified users and/or groups.
Expand All @@ -38,6 +39,11 @@ def send_email(
List of user IDs to send the email to.
group_ids : List[UUID], optional
List of group IDs to send the email to. All members of these groups will receive the email.
attachments : List[dict], optional
List of email attachments. Each attachment should be a dictionary with:
- filename: str - Name of the file
- payload: str - Base64-encoded file content
- type: str - MIME type (e.g., 'text/plain', 'application/pdf')

Returns
-------
Expand Down Expand Up @@ -65,12 +71,29 @@ def send_email(
... subject="Group Notification",
... body="This is a notification for the group."
... )

Send an email with attachments:

>>> import base64
>>> with open('report.pdf', 'rb') as f:
... pdf_content = base64.b64encode(f.read()).decode('utf-8')
>>> result = max.email.send_email(
... user_ids=[uuid.UUID("12345678-1234-1234-1234-123456789abc")],
... subject="Monthly Report",
... body="Please find the attached report.",
... attachments=[{
... 'filename': 'report.pdf',
... 'payload': pdf_content,
... 'type': 'application/pdf'
... }]
... )
"""
mutation_args = {
'userIds': [str(uid) for uid in user_ids] if user_ids else None,
'groupIds': [str(gid) for gid in group_ids] if group_ids else None,
'subject': subject,
'body': body,
'attachments': attachments if attachments else None,
}

op = Operations.mutation.send_email
Expand Down
2 changes: 2 additions & 0 deletions answer_rocket/graphql/operations/email.gql
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ mutation SendEmail(
$groupIds: [UUID!]
$subject: String!
$body: String!
$attachments: [EmailAttachment!]
) {
sendEmail(
userIds: $userIds
groupIds: $groupIds
subject: $subject
body: $body
attachments: $attachments
) {
success
recipientCount
Expand Down
9 changes: 9 additions & 0 deletions answer_rocket/graphql/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ class DatasetSearchInput(sgqlc.types.Input):
name_contains = sgqlc.types.Field(String, graphql_name='nameContains')


class EmailAttachment(sgqlc.types.Input):
__schema__ = schema
__field_names__ = ('filename', 'payload', 'type')
filename = sgqlc.types.Field(sgqlc.types.non_null(String), graphql_name='filename')
payload = sgqlc.types.Field(sgqlc.types.non_null(String), graphql_name='payload')
type = sgqlc.types.Field(sgqlc.types.non_null(String), graphql_name='type')


class FunctionCallMessageInput(sgqlc.types.Input):
__schema__ = schema
__field_names__ = ('name', 'arguments')
Expand Down Expand Up @@ -1602,6 +1610,7 @@ class Mutation(sgqlc.types.Type):
('group_ids', sgqlc.types.Arg(sgqlc.types.list_of(sgqlc.types.non_null(UUID)), graphql_name='groupIds', default=None)),
('subject', sgqlc.types.Arg(sgqlc.types.non_null(String), graphql_name='subject', default=None)),
('body', sgqlc.types.Arg(sgqlc.types.non_null(String), graphql_name='body', default=None)),
('attachments', sgqlc.types.Arg(sgqlc.types.list_of(sgqlc.types.non_null(EmailAttachment)), graphql_name='attachments', default=None)),
))
)

Expand Down
4 changes: 2 additions & 2 deletions answer_rocket/graphql/sdk_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,8 @@ def mutation_delete_dataset_kshot():


def mutation_send_email():
_op = sgqlc.operation.Operation(_schema_root.mutation_type, name='SendEmail', variables=dict(userIds=sgqlc.types.Arg(sgqlc.types.list_of(sgqlc.types.non_null(_schema.UUID))), groupIds=sgqlc.types.Arg(sgqlc.types.list_of(sgqlc.types.non_null(_schema.UUID))), subject=sgqlc.types.Arg(sgqlc.types.non_null(_schema.String)), body=sgqlc.types.Arg(sgqlc.types.non_null(_schema.String))))
_op_send_email = _op.send_email(user_ids=sgqlc.types.Variable('userIds'), group_ids=sgqlc.types.Variable('groupIds'), subject=sgqlc.types.Variable('subject'), body=sgqlc.types.Variable('body'))
_op = sgqlc.operation.Operation(_schema_root.mutation_type, name='SendEmail', variables=dict(userIds=sgqlc.types.Arg(sgqlc.types.list_of(sgqlc.types.non_null(_schema.UUID))), groupIds=sgqlc.types.Arg(sgqlc.types.list_of(sgqlc.types.non_null(_schema.UUID))), subject=sgqlc.types.Arg(sgqlc.types.non_null(_schema.String)), body=sgqlc.types.Arg(sgqlc.types.non_null(_schema.String)), attachments=sgqlc.types.Arg(sgqlc.types.list_of(sgqlc.types.non_null(_schema.EmailAttachment)))))
_op_send_email = _op.send_email(user_ids=sgqlc.types.Variable('userIds'), group_ids=sgqlc.types.Variable('groupIds'), subject=sgqlc.types.Variable('subject'), body=sgqlc.types.Variable('body'), attachments=sgqlc.types.Variable('attachments'))
_op_send_email.success()
_op_send_email.recipient_count()
_op_send_email.error()
Expand Down