"When I send a message using this method:
const { data: message } = await this.nylasService.messages.send({
identifier: account.grantId,
requestBody: data,
});
the message lands in the correct thread. But if I send it with an attachment using form-data, the message ends up in a new thread. Is this the expected behavior?"
public async sendWithGcsAttachments(credentials: Credentials, data: SendNylasMessageDto): Promise<NylasMessage> {
const account = await this.nylasAccountsService.getMe(credentials);
const formData = new FormData();
const gcsAttachments = data.gcsAttachments ?? [];
const messageData = {
...data,
attachments: gcsAttachments.map((att, index) => ({
filename: att.filename,
content_type: att.contentType,
content_id: `file${index}`,
})),
};
formData.append('message', JSON.stringify(messageData));
await Promise.all(
gcsAttachments.map(async (att, i) => {
const stream = this.gcpBucketService.getReadStream(att.gcpUrl);
const metadata = await this.gcpBucketService.getFileMetadata(att.gcpUrl);
const size = Number(metadata.size);
if (Number.isNaN(size)) {
throw new Error(`Invalid file size for ${att.gcpUrl}`);
}
formData.append(`file${i}`, stream, {
filename: att.filename,
contentType: att.contentType,
knownLength: size,
});
}),
);
return (
await this.nylasService.apiClient.request<{ data: NylasMessage }>({
method: 'POST',
path: `/v3/grants/${account.grantId}/messages/send`,
form: formData,
})
).data;
}
not working
In the second method (using form-data), I’m sending the same data and can see that this field (e.g., replyToMessageId or threadId) exists in the form-data. How do I properly pass it to ensure the message lands in the correct thread?
thx