mirror of
				https://github.com/lingble/chatwoot.git
				synced 2025-10-31 11:08:04 +00:00 
			
		
		
		
	 3fc646f330
			
		
	
	3fc646f330
	
	
	
		
			
			* add campaign store(getter, actions and mutations) * add campaign store module * add get campaigns api * add fetch campaign action widget load * add specs * code cleanup * trigger campaig api fixes * integrate campaign trigger action * code cleanup * revert changes * trigger api fixes * review fixes * code beautification * chore: Fix multiple campaigns being send because of race condition * chore: rubocop * chore: Fix specs * disable campaigns Co-authored-by: Nithin David Thomas <webofnithin@gmail.com> Co-authored-by: Sojan <sojan@pepalo.com>
		
			
				
	
	
		
			96 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			JavaScript
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			96 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			JavaScript
		
	
	
		
			Executable File
		
	
	
	
	
| import { buildSearchParamsWithLocale } from '../helpers/urlParamsHelper';
 | |
| 
 | |
| const createConversation = params => {
 | |
|   const referrerURL = window.referrerURL || '';
 | |
|   const search = buildSearchParamsWithLocale(window.location.search);
 | |
|   return {
 | |
|     url: `/api/v1/widget/conversations${search}`,
 | |
|     params: {
 | |
|       contact: {
 | |
|         name: params.fullName,
 | |
|         email: params.emailAddress,
 | |
|       },
 | |
|       message: {
 | |
|         content: params.message,
 | |
|         timestamp: new Date().toString(),
 | |
|         referer_url: referrerURL,
 | |
|       },
 | |
|     },
 | |
|   };
 | |
| };
 | |
| 
 | |
| const sendMessage = content => {
 | |
|   const referrerURL = window.referrerURL || '';
 | |
|   const search = buildSearchParamsWithLocale(window.location.search);
 | |
|   return {
 | |
|     url: `/api/v1/widget/messages${search}`,
 | |
|     params: {
 | |
|       message: {
 | |
|         content,
 | |
|         timestamp: new Date().toString(),
 | |
|         referer_url: referrerURL,
 | |
|       },
 | |
|     },
 | |
|   };
 | |
| };
 | |
| 
 | |
| const sendAttachment = ({ attachment }) => {
 | |
|   const { referrerURL = '' } = window;
 | |
|   const timestamp = new Date().toString();
 | |
|   const { file } = attachment;
 | |
| 
 | |
|   const formData = new FormData();
 | |
|   formData.append('message[attachments][]', file, file.name);
 | |
|   formData.append('message[referer_url]', referrerURL);
 | |
|   formData.append('message[timestamp]', timestamp);
 | |
|   return {
 | |
|     url: `/api/v1/widget/messages${window.location.search}`,
 | |
|     params: formData,
 | |
|   };
 | |
| };
 | |
| 
 | |
| const getConversation = ({ before }) => ({
 | |
|   url: `/api/v1/widget/messages${window.location.search}`,
 | |
|   params: { before },
 | |
| });
 | |
| 
 | |
| const updateMessage = id => ({
 | |
|   url: `/api/v1/widget/messages/${id}${window.location.search}`,
 | |
| });
 | |
| 
 | |
| const getAvailableAgents = token => ({
 | |
|   url: '/api/v1/widget/inbox_members',
 | |
|   params: {
 | |
|     website_token: token,
 | |
|   },
 | |
| });
 | |
| const getCampaigns = token => ({
 | |
|   url: '/api/v1/widget/campaigns',
 | |
|   params: {
 | |
|     website_token: token,
 | |
|   },
 | |
| });
 | |
| const triggerCampaign = (token, campaignId) => ({
 | |
|   url: '/api/v1/widget/events',
 | |
|   data: {
 | |
|     name: 'campaign.triggered',
 | |
|     event_info: {
 | |
|       campaign_id: campaignId,
 | |
|     },
 | |
|   },
 | |
|   params: {
 | |
|     website_token: token,
 | |
|   },
 | |
| });
 | |
| 
 | |
| export default {
 | |
|   createConversation,
 | |
|   sendMessage,
 | |
|   sendAttachment,
 | |
|   getConversation,
 | |
|   updateMessage,
 | |
|   getAvailableAgents,
 | |
|   getCampaigns,
 | |
|   triggerCampaign,
 | |
| };
 |