UNPKG

@digitalstories/n8n-nodes-infomaniak

Version:

n8n nodes to interact with Infomaniak services (Kchat)

61 lines 2.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createPost = createPost; exports.listPosts = listPosts; async function createPost(i, baseURL) { const channelId = this.getNodeParameter('channelId', i); const postContent = this.getNodeParameter('postContent', i); const addFile = this.getNodeParameter('addFile', i, false); let fileId; if (addFile) { const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i); const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName); const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName); const formData = { channel_id: channelId, files: { value: dataBuffer, options: { filename: binaryData.fileName, contentType: binaryData.mimeType, }, }, }; const fileResponse = await this.helpers.requestWithAuthentication.call(this, 'infomaniakApi', { method: 'POST', url: `${baseURL}/api/v4/files`, formData, json: true, }); if (fileResponse && fileResponse.file_info && fileResponse.file_info.id) { fileId = fileResponse.file_info.id; } else { throw new Error('Upload de fichier échoué ou réponse inattendue.'); } } const postBody = { channel_id: channelId, message: postContent, }; if (fileId) { postBody.file_ids = [fileId]; } const response = await this.helpers.requestWithAuthentication.call(this, 'infomaniakApi', { method: 'POST', url: `${baseURL}/api/v4/posts`, body: postBody, json: true, }); return response; } async function listPosts(i, baseURL) { const channelId = this.getNodeParameter('channelId', i); const response = await this.helpers.requestWithAuthentication.call(this, 'infomaniakApi', { method: 'GET', url: `${baseURL}/api/v4/channels/${channelId}/posts`, json: true, }); return response; } //# sourceMappingURL=ChannelOperations.js.map