endConversation() method from lightning-conversation-toolkit-api in the Salesforce Lightning Web Component can be used to create custom End Conversation Button for Salesforce Enhanced Channels like Messaging for In-App and Web.
Sample Lightning Web Component:
HTML:
<template>
<lightning-conversation-toolkit-api lwc:ref="lwcToolKitApi">
</lightning-conversation-toolkit-api>
<lightning-card>
<lightning-button
label="End Conversation"
onclick={endConversation} >
</lightning-button>
</lightning-card>
</template>
JavaScript:
import { LightningElement, api } from 'lwc';
export default class EndConversation extends LightningElement {
@api recordId;
async endConversation( event ) {
const toolKit = this.refs.lwcToolKitApi;
let result = await toolKit.endConversation(
this.recordId
);
console.log(
'result is',
result
);
}
}
js-meta.xml:
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>60.0</apiVersion>
<isExposed>true</isExposed>
<targets>
<target>lightning__RecordPage</target>
</targets>
</LightningComponentBundle>