Skip to content

messages

Messages

Bases: ListableApiResource, FindableApiResource, UpdatableApiResource, DestroyableApiResource

Source code in nylas/resources/messages.py
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 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
class Messages(
    ListableApiResource,
    FindableApiResource,
    UpdatableApiResource,
    DestroyableApiResource,
):
    @property
    def smart_compose(self) -> SmartCompose:
        """
        Access the Smart Compose collection of endpoints.

        Returns:
            The Smart Compose collection of endpoints.
        """
        return SmartCompose(self._http_client)

    def list(
        self, identifier: str, query_params: Optional[ListMessagesQueryParams] = None
    ) -> ListResponse[Message]:
        """
        Return all Messages.

        Args:
            identifier: The identifier of the grant to get messages for.
            query_params: The query parameters to filter messages by.

        Returns:
            A list of Messages.
        """
        return super(Messages, self).list(
            path=f"/v3/grants/{identifier}/messages",
            response_type=Message,
            query_params=query_params,
        )

    def find(
        self,
        identifier: str,
        message_id: str,
        query_params: Optional[FindMessageQueryParams] = None,
    ) -> Response[Message]:
        """
        Return a Message.

        Args:
            identifier: The identifier of the grant to get the message for.
            message_id: The identifier of the message to get.
            query_params: The query parameters to include in the request.

        Returns:
            The requested Message.
        """
        return super(Messages, self).find(
            path=f"/v3/grants/{identifier}/messages/{message_id}",
            response_type=Message,
            query_params=query_params,
        )

    def update(
        self,
        identifier: str,
        message_id: str,
        request_body: UpdateMessageRequest,
    ) -> Response[Message]:
        """
        Update a Message.

        Args:
            identifier: The identifier of the grant to update the message for.
            message_id: The identifier of the message to update.
            request_body: The request body to update the message with.
            query_params: The query parameters to include in the request.

        Returns:
            The updated Message.
        """
        return super(Messages, self).update(
            path=f"/v3/grants/{identifier}/messages/{message_id}",
            response_type=Message,
            request_body=request_body,
        )

    def destroy(self, identifier: str, message_id: str) -> DeleteResponse:
        """
        Delete a Message.

        Args:
            identifier: The identifier of the grant to delete the message for.
            message_id: The identifier of the message to delete.

        Returns:
            The deletion response.
        """
        return super(Messages, self).destroy(
            path=f"/v3/grants/{identifier}/messages/{message_id}",
        )

    def send(
        self, identifier: str, request_body: SendMessageRequest
    ) -> Response[Message]:
        """
        Send a Message.

        Args:
            identifier: The identifier of the grant to send the message for.
            request_body: The request body to send the message with.

        Returns:
            The sent message.
        """
        json_response = self._http_client._execute(
            method="POST",
            path=f"/v3/grants/{identifier}/messages/send",
            data=_build_form_request(request_body),
        )

        return Response.from_dict(json_response, Message)

    def list_scheduled_messages(
        self, identifier: str
    ) -> Response[ScheduledMessagesList]:
        """
        Retrieve your scheduled messages.

        Args:
            identifier: The identifier of the grant to delete the message for.

        Returns:
            Response: The list of scheduled messages.
        """
        json_response = self._http_client._execute(
            method="GET",
            path=f"/v3/grants/{identifier}/messages/schedules",
        )

        return Response.from_dict(json_response, ScheduledMessagesList)

    def find_scheduled_message(
        self, identifier: str, schedule_id: str
    ) -> Response[ScheduledMessage]:
        """
        Retrieve your scheduled messages.

        Args:
            identifier: The identifier of the grant to delete the message for.
            schedule_id: The id of the scheduled message to retrieve.

        Returns:
            Response: The scheduled message.
        """
        json_response = self._http_client._execute(
            method="GET",
            path=f"/v3/grants/{identifier}/messages/schedules/{schedule_id}",
        )

        return Response.from_dict(json_response, ScheduledMessage)

    def stop_scheduled_message(
        self, identifier: str, schedule_id: str
    ) -> Response[StopScheduledMessageResponse]:
        """
        Stop a scheduled message.

        Args:
            identifier: The identifier of the grant to delete the message for.
            schedule_id: The id of the scheduled message to stop.

        Returns:
            Response: The confirmation of the stopped scheduled message.
        """
        json_response = self._http_client._execute(
            method="DELETE",
            path=f"/v3/grants/{identifier}/messages/schedules/{schedule_id}",
        )

        return Response.from_dict(json_response, StopScheduledMessageResponse)

smart_compose: SmartCompose property

Access the Smart Compose collection of endpoints.

Returns:

Type Description
SmartCompose

The Smart Compose collection of endpoints.

destroy(identifier, message_id)

Delete a Message.

Parameters:

Name Type Description Default
identifier str

The identifier of the grant to delete the message for.

required
message_id str

The identifier of the message to delete.

required

Returns:

Type Description
DeleteResponse

The deletion response.

Source code in nylas/resources/messages.py
106
107
108
109
110
111
112
113
114
115
116
117
118
119
def destroy(self, identifier: str, message_id: str) -> DeleteResponse:
    """
    Delete a Message.

    Args:
        identifier: The identifier of the grant to delete the message for.
        message_id: The identifier of the message to delete.

    Returns:
        The deletion response.
    """
    return super(Messages, self).destroy(
        path=f"/v3/grants/{identifier}/messages/{message_id}",
    )

find(identifier, message_id, query_params=None)

Return a Message.

Parameters:

Name Type Description Default
identifier str

The identifier of the grant to get the message for.

required
message_id str

The identifier of the message to get.

required
query_params Optional[FindMessageQueryParams]

The query parameters to include in the request.

None

Returns:

Type Description
Response[Message]

The requested Message.

Source code in nylas/resources/messages.py
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
def find(
    self,
    identifier: str,
    message_id: str,
    query_params: Optional[FindMessageQueryParams] = None,
) -> Response[Message]:
    """
    Return a Message.

    Args:
        identifier: The identifier of the grant to get the message for.
        message_id: The identifier of the message to get.
        query_params: The query parameters to include in the request.

    Returns:
        The requested Message.
    """
    return super(Messages, self).find(
        path=f"/v3/grants/{identifier}/messages/{message_id}",
        response_type=Message,
        query_params=query_params,
    )

find_scheduled_message(identifier, schedule_id)

Retrieve your scheduled messages.

Parameters:

Name Type Description Default
identifier str

The identifier of the grant to delete the message for.

required
schedule_id str

The id of the scheduled message to retrieve.

required

Returns:

Name Type Description
Response Response[ScheduledMessage]

The scheduled message.

Source code in nylas/resources/messages.py
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
def find_scheduled_message(
    self, identifier: str, schedule_id: str
) -> Response[ScheduledMessage]:
    """
    Retrieve your scheduled messages.

    Args:
        identifier: The identifier of the grant to delete the message for.
        schedule_id: The id of the scheduled message to retrieve.

    Returns:
        Response: The scheduled message.
    """
    json_response = self._http_client._execute(
        method="GET",
        path=f"/v3/grants/{identifier}/messages/schedules/{schedule_id}",
    )

    return Response.from_dict(json_response, ScheduledMessage)

list(identifier, query_params=None)

Return all Messages.

Parameters:

Name Type Description Default
identifier str

The identifier of the grant to get messages for.

required
query_params Optional[ListMessagesQueryParams]

The query parameters to filter messages by.

None

Returns:

Type Description
ListResponse[Message]

A list of Messages.

Source code in nylas/resources/messages.py
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
def list(
    self, identifier: str, query_params: Optional[ListMessagesQueryParams] = None
) -> ListResponse[Message]:
    """
    Return all Messages.

    Args:
        identifier: The identifier of the grant to get messages for.
        query_params: The query parameters to filter messages by.

    Returns:
        A list of Messages.
    """
    return super(Messages, self).list(
        path=f"/v3/grants/{identifier}/messages",
        response_type=Message,
        query_params=query_params,
    )

list_scheduled_messages(identifier)

Retrieve your scheduled messages.

Parameters:

Name Type Description Default
identifier str

The identifier of the grant to delete the message for.

required

Returns:

Name Type Description
Response Response[ScheduledMessagesList]

The list of scheduled messages.

Source code in nylas/resources/messages.py
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
def list_scheduled_messages(
    self, identifier: str
) -> Response[ScheduledMessagesList]:
    """
    Retrieve your scheduled messages.

    Args:
        identifier: The identifier of the grant to delete the message for.

    Returns:
        Response: The list of scheduled messages.
    """
    json_response = self._http_client._execute(
        method="GET",
        path=f"/v3/grants/{identifier}/messages/schedules",
    )

    return Response.from_dict(json_response, ScheduledMessagesList)

send(identifier, request_body)

Send a Message.

Parameters:

Name Type Description Default
identifier str

The identifier of the grant to send the message for.

required
request_body SendMessageRequest

The request body to send the message with.

required

Returns:

Type Description
Response[Message]

The sent message.

Source code in nylas/resources/messages.py
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
def send(
    self, identifier: str, request_body: SendMessageRequest
) -> Response[Message]:
    """
    Send a Message.

    Args:
        identifier: The identifier of the grant to send the message for.
        request_body: The request body to send the message with.

    Returns:
        The sent message.
    """
    json_response = self._http_client._execute(
        method="POST",
        path=f"/v3/grants/{identifier}/messages/send",
        data=_build_form_request(request_body),
    )

    return Response.from_dict(json_response, Message)

stop_scheduled_message(identifier, schedule_id)

Stop a scheduled message.

Parameters:

Name Type Description Default
identifier str

The identifier of the grant to delete the message for.

required
schedule_id str

The id of the scheduled message to stop.

required

Returns:

Name Type Description
Response Response[StopScheduledMessageResponse]

The confirmation of the stopped scheduled message.

Source code in nylas/resources/messages.py
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
def stop_scheduled_message(
    self, identifier: str, schedule_id: str
) -> Response[StopScheduledMessageResponse]:
    """
    Stop a scheduled message.

    Args:
        identifier: The identifier of the grant to delete the message for.
        schedule_id: The id of the scheduled message to stop.

    Returns:
        Response: The confirmation of the stopped scheduled message.
    """
    json_response = self._http_client._execute(
        method="DELETE",
        path=f"/v3/grants/{identifier}/messages/schedules/{schedule_id}",
    )

    return Response.from_dict(json_response, StopScheduledMessageResponse)

update(identifier, message_id, request_body)

Update a Message.

Parameters:

Name Type Description Default
identifier str

The identifier of the grant to update the message for.

required
message_id str

The identifier of the message to update.

required
request_body UpdateMessageRequest

The request body to update the message with.

required
query_params

The query parameters to include in the request.

required

Returns:

Type Description
Response[Message]

The updated Message.

Source code in nylas/resources/messages.py
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
def update(
    self,
    identifier: str,
    message_id: str,
    request_body: UpdateMessageRequest,
) -> Response[Message]:
    """
    Update a Message.

    Args:
        identifier: The identifier of the grant to update the message for.
        message_id: The identifier of the message to update.
        request_body: The request body to update the message with.
        query_params: The query parameters to include in the request.

    Returns:
        The updated Message.
    """
    return super(Messages, self).update(
        path=f"/v3/grants/{identifier}/messages/{message_id}",
        response_type=Message,
        request_body=request_body,
    )