Skip to content

Commit

Permalink
Add support for a dynamic window.intergramOnOpen.visitorName property…
Browse files Browse the repository at this point in the history
… 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)
  • Loading branch information
idoco committed Jul 24, 2017
1 parent 8067058 commit 6c7bccb
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(){
Expand Down
2 changes: 1 addition & 1 deletion src/chat/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
3 changes: 2 additions & 1 deletion src/widget/chat-frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<iframe src={iFrameSrc + '?id=' + intergramId + '&host=' + host + '&conf=' + encodedConf }
width='100%'
Expand Down

0 comments on commit 6c7bccb

Please sign in to comment.