diff --git a/answer_rocket/email.py b/answer_rocket/email.py index e60cf35..8fc4899 100644 --- a/answer_rocket/email.py +++ b/answer_rocket/email.py @@ -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. @@ -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 ------- @@ -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 diff --git a/answer_rocket/graphql/operations/email.gql b/answer_rocket/graphql/operations/email.gql index d159a1e..29919b9 100644 --- a/answer_rocket/graphql/operations/email.gql +++ b/answer_rocket/graphql/operations/email.gql @@ -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 diff --git a/answer_rocket/graphql/schema.py b/answer_rocket/graphql/schema.py index 1afcf7b..64e345d 100644 --- a/answer_rocket/graphql/schema.py +++ b/answer_rocket/graphql/schema.py @@ -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') @@ -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)), )) ) diff --git a/answer_rocket/graphql/sdk_operations.py b/answer_rocket/graphql/sdk_operations.py index 93b1169..c973abd 100644 --- a/answer_rocket/graphql/sdk_operations.py +++ b/answer_rocket/graphql/sdk_operations.py @@ -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()