mirror of
				https://github.com/lingble/chatwoot.git
				synced 2025-11-04 13:07:55 +00:00 
			
		
		
		
	- Adds support for file upload Co-authored-by: Pranav Raj Sreepuram <pranavrajs@gmail.com> Co-authored-by: Sojan <sojan@pepalo.com>
		
			
				
	
	
		
			35 lines
		
	
	
		
			829 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			35 lines
		
	
	
		
			829 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 }]) {
 | 
						|
    const formData = new FormData();
 | 
						|
    formData.append('attachment[file]', file);
 | 
						|
    return axios({
 | 
						|
      method: 'post',
 | 
						|
      url: `${this.url}/${conversationId}/messages`,
 | 
						|
      data: formData,
 | 
						|
    });
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
export default new MessageApi();
 |