2

Recently I am trying to use Twilio Flex Web Chat in my project and I am using a pre-engagement form for collecting user names. In the pre-engagement form based on the data collected I want to show a welcome message.I have tried this code but seems it is not working and in Twilio documentation, I can't find how to do it. Below is my code .

Twilio.FlexWebChat.createWebChat(appConfig).then(webchat => {
        const { manager } = webchat;
        debugger;
    //Posting question from preengagement form as users first chat message
        Twilio.FlexWebChat.Actions.on("afterStartEngagement", (payload) => {
            const { question, friendlyName } = payload.formData;
            manager.strings.PredefinedChatMessageBody  = `Hi !! ${friendlyName} How we can help you?`;
            if (!question)
                return;

            const { channelSid } = manager.store.getState().flex.session;
            manager
                .chatClient.getChannelBySid(channelSid)
                .then(channel => channel.sendMessage(question));
        });
    // Changing the Welcome message
        manager.strings.WelcomeMessage = "Welcome to AppsEconnect";
        manager.strings.PredefinedChatMessageAuthorName = "Appseconnect Team";
        manager.strings.PredefinedChatMessageBody  = "{{friendlyName}} how we can help you ?";

    // Render WebChat
        webchat.init();
    });
Utpal
  • 805
  • 4
  • 15
  • 44

1 Answers1

0

Check if this answer works for you:

Twilio.FlexWebChat.MainContainer.defaultProps.startEngagementOnInit = false;  
    manager.strings.WelcomeMessage = "Holi como estamos desgraciaoo";
    Twilio.FlexWebChat.MessagingCanvas.defaultProps.predefinedMessage.body = '¡Bienvenido!  ¿Con quién tengo el gusto de hablar?'
// Render WebChat
    webchat.init();
dbc
  • 104,963
  • 20
  • 228
  • 340
  • Hello, and welcome to stack overflow. Thanks for posting this, but all posts to stack overflow are requested to be in English. See [here](https://meta.stackoverflow.com/a/297680/) for details. In this case I translated the Spanish to English for you, but in general if you don't post in English your post may get removed. And please do check to make sure my translation is correct. – dbc Nov 10 '22 at 19:30