-
Notifications
You must be signed in to change notification settings - Fork 10.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NEW] Livechat webhook request on message #9870
Changes from 11 commits
2d773c3
3fdfb9a
050d3ff
027aa61
98d4f86
7a1e3b5
110c408
cf6b051
e51c259
b4e8fb9
a0de294
ecb7739
2f5fdf3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,15 +5,24 @@ function sendToCRM(type, room, includeMessages = true) { | |
|
||
postData.messages = []; | ||
|
||
if (includeMessages) { | ||
RocketChat.models.Messages.findVisibleByRoomId(room._id, { sort: { ts: 1 } }).forEach((message) => { | ||
let messages; | ||
if (typeof includeMessages === 'boolean' && includeMessages) { | ||
messages = RocketChat.models.Messages.findVisibleByRoomId(room._id, { sort: { ts: 1 } }); | ||
} else if (includeMessages instanceof Array) { | ||
messages = includeMessages; | ||
} | ||
|
||
if (messages) { | ||
messages.forEach((message) => { | ||
if (message.t) { | ||
return; | ||
} | ||
const msg = { | ||
_id: message._id, | ||
username: message.u.username, | ||
msg: message.msg, | ||
ts: message.ts | ||
ts: message.ts, | ||
editedAt: message.editedAt | ||
}; | ||
|
||
if (message.u.username !== postData.visitor.username) { | ||
|
@@ -49,6 +58,31 @@ RocketChat.callbacks.add('livechat.saveInfo', (room) => { | |
return sendToCRM('LivechatEdit', room); | ||
}, RocketChat.callbacks.priority.MEDIUM, 'livechat-send-crm-save-info'); | ||
|
||
RocketChat.callbacks.add('afterSaveMessage', function(message, room) { | ||
// only call webhook if it is a livechat room | ||
if (!(typeof room.t !== 'undefined' && room.t === 'l' && room.v && room.v.token)) { | ||
return message; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will pass if if (room.t !== 'l' || room.v == null || room.v.token == null)) { There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rodrigok, fix was done according to suggestion. |
||
|
||
// if the message has a token, it was sent from the visitor | ||
// if not, it was sent from the agent | ||
if (message.token) { | ||
if (!RocketChat.settings.get('Livechat_webhook_on_visitor_message')) { | ||
return message; | ||
} | ||
} else if (!RocketChat.settings.get('Livechat_webhook_on_agent_message')) { | ||
return message; | ||
} | ||
|
||
// if the message has a type means it is a special message (like the closing comment), so skips | ||
if (message.t) { | ||
return message; | ||
} | ||
|
||
sendToCRM('Message', room, [message]); | ||
return message; | ||
}, RocketChat.callbacks.priority.MEDIUM, 'sendMessageToFacebook'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The callback ID/name is wrong There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rodrigok, fixed callback ID to |
||
|
||
RocketChat.callbacks.add('livechat.leadCapture', (room) => { | ||
if (!RocketChat.settings.get('Livechat_webhook_on_capture')) { | ||
return room; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sampaiodiego here I added
_id
andeditedAt
fields. This is the payload sent on webhook request. Now, these new fields will be sent in all events.