So, I am following along the tutorial here on how to setup Twilio Flex WebChat. While it certainly works, I need to change the friendly name later on.
The way my app works, it shows the webchat before users sign since the scripts are in the index.html file of the react app.
I need to change it so that after they login it will update the name displayed in the chat.
This is what I have so far, but it certainly doesn't work. Assume I can get the names from local storage, and login stuff works.
componentDidMount() {
//other stuff
this.initializeTwilio();
}
initializeTwilio() {
const name = localStorage.getItem("firstName") +' '+ localStorage.getItem("lastName");
const appConfig = {
accountSid :"hidden",
flexFlowSid: "hidden",
context: {
friendlyName: name
}
};
Twilio.FlexWebChat.renderWebChat(appConfig);
}
I have also tried doing this:
let test = Twilio.FlexWebChat.Manager.create(appConfig);
Twilio.FlexWebChat.ContextProvider.Manager = test;
Twilio.FlexWebChat.renderWebChat(appConfig);
I have also tried editing the MessagingCanvas like so:
initializeTwilio =() => {
const first = localStorage.getItem("firstName");
let name ="";
if(first){
const last = localStorage.getItem("lastName");
name = first +' '+ last;
}
else {
name = "Anonymous";
}
Twilio.FlexWebChat.MessagingCanvas.defaultProps.memberDisplayOptions = {
yourDefaultName: name,
yourFriendlyNameOverride: true
}
console.log(Twilio.FlexWebChat.MessagingCanvas.defaultProps);
}
This will change the value in the console but not the displayed name in the chat window.
I think I need to update the appconfig and re-render the chat window, but not sure how to do it and there may be a different way to solve the problem. I am open to being enlightened on this one.