Skip to main content

How can I auto start chat in preChat(LWC) when the page loaded and the condition is true.  

 I tried to do the code below

import BasePrechat from 'lightningsnapin/basePrechat';

import { api, track } from 'lwc';

import startChatLabel from '@salesforce/label/c.StartChat';

export default class Prechat extends BasePrechat {

@api prechatFields;

@api backgroundImgURL;

@track fields;

@track namelist;#Chatbot

startChatLabel;

test = 'test';

// test = '';

connectedCallback() {

this.startChatLabel = startChatLabel;

this.fields = this.prechatFields.map(field => {

const { label, name, value, required, maxLength } = field;

return { label, value, name, required, maxLength };

});

this.namelist = this.fields.map(field => field.name);

if (this.test != '') {

this.handleStartChat();

}

}

renderedCallback() {

this.template.querySelector("lightning-input").focus();

}

handleStartChat() {

this.template.querySelectorAll("lightning-input").forEach(input => {

this.fields[this.namelist.indexOf(input.name)].value = input.value;

});

if (this.validateFields(this.fields).valid) {

this.startChat(this.fields);

} else {

// Error handling if fields do not pass validation.

}

}

}

 But the error below occurs

How can I auto start chat in preChat(LWC) when the page loaded and the condition is true

 

How can I solve this problem?  Thank you! 

 

#Salesforce Developer

2 件の回答
0/9000