FredrikOseberg / react-chatbot-kit

MIT License
325 stars 155 forks source link

Changing the bot initial message dynamically #107

Closed shubham-vEngageAi closed 2 years ago

shubham-vEngageAi commented 2 years ago

Hi FredrikOseberg, I want to change the bot initial message dynamically. But I am unable to do that. please can you tell me the way to do that? This requirement is very important for us .

Thanks and regards Shubham Kumar

FredrikOseberg commented 2 years ago

Hi FredrikOseberg, I want to change the bot initial message dynamically. But I am unable to do that. please can you tell me the way to do that? This requirement is very important for us .

Thanks and regards Shubham Kumar

You could wrap the config in a function, and provide the initial message as a parameter to that function:

getConfig = (message) => ({ initialMessages: [createChatBotMessage(message)] })

skmainwal commented 2 years ago

Getting an Error

config.js

image

I want to pass the message to ChatBot from APP.js

image but i am getting an error image

pompy commented 1 year ago

You can add as many dynamic messages as possible - even via rest api Just make config dynamic ;-)

const botinitconfig = { botid: 111, botheader: 'Pompy Bot', startertext: 'Welcome', botMessageBox: '#376B7E', chatButton:'#5ccc9d', initialMessages: init() }

const init = () => { var initMessages = ['Welcome', 'Pompy', 'Dynamic Init Message Works']; return ( initMessages.map(function (message, index) { return createChatBotMessage(message) })) }

<Route path="/" element={< ChatBotPage botinit={botinitconfig} / >}/>