791d90c6b7
At present, the websocket pubsub tokens are present at the contact objects in chatwoot. A better approach would be to have these tokens at the contact_inbox object instead. This helps chatwoot to deliver the websocket events targetted to the specific widget connection, stop contact events from leaking into other chat sessions from the same contact. Fixes #1682 Fixes #1664 Co-authored-by: Pranav Raj S <pranav@chatwoot.com> Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
36 lines
930 B
JavaScript
36 lines
930 B
JavaScript
export const stripTrailingSlash = ({ URL }) => {
|
|
return URL.replace(/\/$/, '');
|
|
};
|
|
|
|
// Format all campaigns
|
|
export const formatCampaigns = ({ campaigns }) => {
|
|
return campaigns.map(item => {
|
|
return {
|
|
id: item.id,
|
|
triggerOnlyDuringBusinessHours:
|
|
item.trigger_only_during_business_hours || false,
|
|
timeOnPage: item?.trigger_rules?.time_on_page,
|
|
url: item?.trigger_rules?.url,
|
|
};
|
|
});
|
|
};
|
|
|
|
// Filter all campaigns based on current URL and business availability time
|
|
export const filterCampaigns = ({
|
|
campaigns,
|
|
currentURL,
|
|
isInBusinessHours,
|
|
}) => {
|
|
return campaigns.filter(campaign => {
|
|
const hasMatchingURL =
|
|
stripTrailingSlash({ URL: campaign.url }) ===
|
|
stripTrailingSlash({ URL: currentURL });
|
|
if (!hasMatchingURL) {
|
|
return false;
|
|
}
|
|
if (campaign.triggerOnlyDuringBusinessHours) {
|
|
return isInBusinessHours;
|
|
}
|
|
return true;
|
|
});
|
|
};
|