From 6c7bccb37175f1ff8f374fb383e73de66b3f5047 Mon Sep 17 00:00:00 2001 From: idoco Date: Mon, 24 Jul 2017 13:41:39 +0300 Subject: [PATCH] Add support for a dynamic window.intergramOnOpen.visitorName property that is passed to the chat only when its opened and displays additional user data in the telegram chat on every message it sends. (cherry picked from commit 233499b) --- server.js | 3 ++- src/chat/chat.js | 2 +- src/widget/chat-frame.js | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/server.js b/server.js index 9b4f60f..28facee 100644 --- a/server.js +++ b/server.js @@ -53,7 +53,8 @@ io.on('connection', function(client){ client.on('message', function(msg) { messageReceived = true; io.emit(chatId + "-" + userId, msg); - sendTelegramMessage(chatId, userId + ": " + msg.text); + let visitorName = msg.visitorName ? "[" + msg.visitorName + "]: " : ""; + sendTelegramMessage(chatId, userId + ":" + visitorName + " " + msg.text); }); client.on('disconnect', function(){ diff --git a/src/chat/chat.js b/src/chat/chat.js index cca8a43..b032ab0 100644 --- a/src/chat/chat.js +++ b/src/chat/chat.js @@ -51,7 +51,7 @@ export default class Chat extends Component { handleKeyPress = (e) => { if (e.keyCode == 13 && this.input.value) { let text = this.input.value; - this.socket.send({text, from: 'visitor'}); + this.socket.send({text, from: 'visitor', visitorName: this.props.conf.visitorName}); this.input.value = ''; if (this.autoResponseState === 'pristine') { diff --git a/src/widget/chat-frame.js b/src/widget/chat-frame.js index d3944ed..2aa5661 100644 --- a/src/widget/chat-frame.js +++ b/src/widget/chat-frame.js @@ -8,7 +8,8 @@ export default class ChatFrame extends Component { } render({intergramId, host, iFrameSrc, isMobile, conf},{}) { - let encodedConf = encodeURIComponent(JSON.stringify(conf)); + let dynamicConf = window.intergramOnOpen || {}; // these configuration are loaded when the chat frame is opened + let encodedConf = encodeURIComponent(JSON.stringify({...conf, ...dynamicConf})); return (