mirror of
				https://github.com/lingble/chatwoot.git
				synced 2025-10-30 18:47:51 +00:00 
			
		
		
		
	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:
		| @@ -203,6 +203,13 @@ export const IFrameHelper = { | |||||||
|       updateCampaignReadStatus(window.$chatwoot.baseDomain); |       updateCampaignReadStatus(window.$chatwoot.baseDomain); | ||||||
|     }, |     }, | ||||||
|  |  | ||||||
|  |     postback(data) { | ||||||
|  |       dispatchWindowEvent({ | ||||||
|  |         eventName: 'chatwoot:postback', | ||||||
|  |         data, | ||||||
|  |       }); | ||||||
|  |     }, | ||||||
|  |  | ||||||
|     toggleBubble: state => { |     toggleBubble: state => { | ||||||
|       let bubbleState = {}; |       let bubbleState = {}; | ||||||
|       if (state === 'open') { |       if (state === 'open') { | ||||||
|   | |||||||
| @@ -1,6 +1,8 @@ | |||||||
| <script> | <script> | ||||||
| import { mapGetters } from 'vuex'; | import { mapGetters } from 'vuex'; | ||||||
| import { getContrastingTextColor } from '@chatwoot/utils'; | import { getContrastingTextColor } from '@chatwoot/utils'; | ||||||
|  | import { IFrameHelper } from 'widget/helpers/utils'; | ||||||
|  |  | ||||||
| export default { | export default { | ||||||
|   components: {}, |   components: {}, | ||||||
|   props: { |   props: { | ||||||
| @@ -22,7 +24,15 @@ export default { | |||||||
|   }, |   }, | ||||||
|   methods: { |   methods: { | ||||||
|     onClick() { |     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 }, | ||||||
|  |           }); | ||||||
|  |         } | ||||||
|  |       } | ||||||
|     }, |     }, | ||||||
|   }, |   }, | ||||||
| }; | }; | ||||||
|   | |||||||
| @@ -62,6 +62,10 @@ window.addEventListener('chatwoot:on-message', function(e) { | |||||||
|   console.log('chatwoot:on-message', e.detail) |   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) { | window.addEventListener('chatwoot:on-start-conversation', function(e) { | ||||||
|   console.log('chatwoot:on-start-conversation', e.detail) |   console.log('chatwoot:on-start-conversation', e.detail) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Shivam Mishra
					Shivam Mishra