mirror of
				https://github.com/lingble/chatwoot.git
				synced 2025-10-31 19:17:48 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			36 lines
		
	
	
		
			897 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			36 lines
		
	
	
		
			897 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| /* eslint no-console: 0 */
 | |
| /* global axios */
 | |
| import ApiClient from '../ApiClient';
 | |
| 
 | |
| class MessageApi extends ApiClient {
 | |
|   constructor() {
 | |
|     super('conversations', { accountScoped: true });
 | |
|   }
 | |
| 
 | |
|   create({ conversationId, message, private: isPrivate }) {
 | |
|     return axios.post(`${this.url}/${conversationId}/messages`, {
 | |
|       message,
 | |
|       private: isPrivate,
 | |
|     });
 | |
|   }
 | |
| 
 | |
|   getPreviousMessages({ conversationId, before }) {
 | |
|     return axios.get(`${this.url}/${conversationId}/messages`, {
 | |
|       params: { before },
 | |
|     });
 | |
|   }
 | |
| 
 | |
|   sendAttachment([conversationId, { file, file_type }]) {
 | |
|     const formData = new FormData();
 | |
|     formData.append('attachment[file]', file);
 | |
|     formData.append('attachment[file_type]', file_type);
 | |
|     return axios({
 | |
|       method: 'post',
 | |
|       url: `${this.url}/${conversationId}/messages`,
 | |
|       data: formData,
 | |
|     });
 | |
|   }
 | |
| }
 | |
| 
 | |
| export default new MessageApi();
 | 
