feat: Support card message postback event as widget event (#11133)

Fixes https://github.com/chatwoot/chatwoot/issues/5956
Fixes https://github.com/chatwoot/chatwoot/issues/1895
This commit is contained in:
Shivam Mishra
2025-03-21 00:30:24 +05:30
committed by GitHub
parent 91b7785dfe
commit 9cf2bd284b
3 changed files with 22 additions and 1 deletions

View File

@@ -203,6 +203,13 @@ export const IFrameHelper = {
updateCampaignReadStatus(window.$chatwoot.baseDomain);
},
postback(data) {
dispatchWindowEvent({
eventName: 'chatwoot:postback',
data,
});
},
toggleBubble: state => {
let bubbleState = {};
if (state === 'open') {

View File

@@ -1,6 +1,8 @@
<script>
import { mapGetters } from 'vuex';
import { getContrastingTextColor } from '@chatwoot/utils';
import { IFrameHelper } from 'widget/helpers/utils';
export default {
components: {},
props: {
@@ -22,7 +24,15 @@ export default {
},
methods: {
onClick() {
// Do postback here
if (this.action.type === 'postback') {
// Send message to parent iframe
if (IFrameHelper.isIFrame()) {
IFrameHelper.sendMessage({
event: 'postback',
data: { payload: this.action.payload },
});
}
}
},
},
};

View File

@@ -62,6 +62,10 @@ window.addEventListener('chatwoot:on-message', function(e) {
console.log('chatwoot:on-message', e.detail)
})
window.addEventListener('chatwoot:postback', function(e) {
console.log('chatwoot:postback', e.detail)
})
window.addEventListener('chatwoot:on-start-conversation', function(e) {
console.log('chatwoot:on-start-conversation', e.detail)