chore: Add custom attributes in campaign.triggered event (#4463)
This commit is contained in:
@@ -155,13 +155,14 @@ export default {
|
||||
this.replaceRoute('prechat-form');
|
||||
} else {
|
||||
this.replaceRoute('messages');
|
||||
bus.$emit('execute-campaign', this.activeCampaign.id);
|
||||
bus.$emit('execute-campaign', { campaignId: this.activeCampaign.id });
|
||||
}
|
||||
this.unsetUnreadView();
|
||||
});
|
||||
bus.$on('execute-campaign', campaignId => {
|
||||
bus.$on('execute-campaign', campaignDetails => {
|
||||
const { customAttributes, campaignId } = campaignDetails;
|
||||
const { websiteToken } = window.chatwootWebChannel;
|
||||
this.executeCampaign({ campaignId, websiteToken });
|
||||
this.executeCampaign({ campaignId, websiteToken, customAttributes });
|
||||
this.replaceRoute('messages');
|
||||
});
|
||||
},
|
||||
|
||||
@@ -7,9 +7,16 @@ const getCampaigns = async websiteToken => {
|
||||
return result;
|
||||
};
|
||||
|
||||
const triggerCampaign = async ({ campaignId, websiteToken }) => {
|
||||
const urlData = endPoints.triggerCampaign({ websiteToken, campaignId });
|
||||
|
||||
const triggerCampaign = async ({
|
||||
campaignId,
|
||||
websiteToken,
|
||||
customAttributes,
|
||||
}) => {
|
||||
const urlData = endPoints.triggerCampaign({
|
||||
websiteToken,
|
||||
campaignId,
|
||||
customAttributes,
|
||||
});
|
||||
await API.post(
|
||||
urlData.url,
|
||||
{ ...urlData.data },
|
||||
@@ -18,5 +25,4 @@ const triggerCampaign = async ({ campaignId, websiteToken }) => {
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
export { getCampaigns, triggerCampaign };
|
||||
|
||||
@@ -78,12 +78,13 @@ const getCampaigns = token => ({
|
||||
website_token: token,
|
||||
},
|
||||
});
|
||||
const triggerCampaign = ({ websiteToken, campaignId }) => ({
|
||||
const triggerCampaign = ({ websiteToken, campaignId, customAttributes }) => ({
|
||||
url: '/api/v1/widget/events',
|
||||
data: {
|
||||
name: 'campaign.triggered',
|
||||
event_info: {
|
||||
campaign_id: campaignId,
|
||||
custom_attributes: customAttributes,
|
||||
...generateEventParams(),
|
||||
},
|
||||
},
|
||||
|
||||
@@ -92,14 +92,17 @@ export const actions = {
|
||||
}
|
||||
},
|
||||
|
||||
executeCampaign: async ({ commit }, { campaignId, websiteToken }) => {
|
||||
executeCampaign: async (
|
||||
{ commit },
|
||||
{ campaignId, websiteToken, customAttributes }
|
||||
) => {
|
||||
try {
|
||||
commit(
|
||||
'conversation/setConversationUIFlag',
|
||||
{ isCreating: true },
|
||||
{ root: true }
|
||||
);
|
||||
await triggerCampaign({ campaignId, websiteToken });
|
||||
await triggerCampaign({ campaignId, websiteToken, customAttributes });
|
||||
commit('setCampaignExecuted', true);
|
||||
commit('setActiveCampaign', {});
|
||||
} catch (error) {
|
||||
|
||||
@@ -46,7 +46,10 @@ export default {
|
||||
conversationCustomAttributes,
|
||||
}) {
|
||||
if (activeCampaignId) {
|
||||
bus.$emit('execute-campaign', activeCampaignId);
|
||||
bus.$emit('execute-campaign', {
|
||||
campaignId: activeCampaignId,
|
||||
customAttributes: conversationCustomAttributes,
|
||||
});
|
||||
this.$store.dispatch('contacts/update', {
|
||||
user: {
|
||||
email: emailAddress,
|
||||
|
||||
Reference in New Issue
Block a user