-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
[NEW] Livechat webhook request on message #9870
Conversation
@@ -49,6 +56,36 @@ 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) { | |||
// skips this callback if the message was edited | |||
if (message.editedAt) { |
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.
should message editings be sent as well?
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.
I think that it could be sent with an indicator to show that message was edited. So, if necessary, we can ignore edited message when the original message was already forward to a channel without edition/update feature.
What do you think?
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.
I agree. the test on the other could be the same to see if the message was edited 👍
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 I think if we will send edited messages we need to send messages ID too. This is to allow the external system make a relationship between original and edited message.
Right?
Follow two examples of payload with "editedAt" and "_id" fields in message item.
A payload example of an original message:
{"_id":"T87nT6cjn8N2BG5X4","label":"HHHH2","code":55,"createdAt":"2018-03-01T19:52:37.522Z","lastMessageAt":"2018-03-09T18:14:55.015Z","visitor":{"_id":"n3Q4Lb29zW9pHpYy4","token":"aaaaaaaaa123ddd456ddd","name":"HHHH2","username":"guest-54","email":[{"address":"[email protected]"}],"phone":null},"agent":{"_id":"a7srSSKZ463Mc5Skw","username":"henrique.magarotto","name":"henrique","email":"[email protected]"},"type":"Message","messages":[{"_id":"o3FaFsuMdmn5J7QCz","username":"henrique.magarotto","msg":"Test message","ts":"2018-03-09T18:18:19.654Z","agentId":"a7srSSKZ463Mc5Skw"}]}
A payload example of an edited message:
{"_id":"T87nT6cjn8N2BG5X4","label":"HHHH2","code":55,"createdAt":"2018-03-01T19:52:37.522Z","lastMessageAt":"2018-03-09T18:18:19.654Z","visitor":{"_id":"n3Q4Lb29zW9pHpYy4","token":"aaaaaaaaa123ddd456ddd","name":"HHHH2","username":"guest-54","email":[{"address":"[email protected]"}],"phone":null},"agent":{"_id":"a7srSSKZ463Mc5Skw","username":"henrique.magarotto","name":"henrique","email":"[email protected]"},"type":"Message","messages":[{"_id":"o3FaFsuMdmn5J7QCz","username":"henrique.magarotto","msg":"Test message!","ts":"2018-03-09T18:18:19.654Z","editedAt":"2018-03-09T18:18:51.485Z","agentId":"a7srSSKZ463Mc5Skw"}]}
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.
right. I think _id
is already included.. if we send edited messages, editedAt
will be sent as well 😉
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, _id
and editedAt
fields of messages was not sent in request JSON as you can see here: https://rocket.chat/docs/administrator-guides/livechat/#integrations
With the changes, this fields will start being sent.
it is becoming even more clear that CRM integration should have been done on top of "outgoing webhooks", this way we could only create events to allow integrations listen to. I think we'll move this way in the near future. |
…tto/Rocket.Chat into livechat-webhook-send-on-message
} | ||
|
||
if (messages) { | ||
messages.forEach((message) => { | ||
if (message.t) { | ||
return; | ||
} | ||
const msg = { |
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
and editedAt
fields. This is the payload sent on webhook request. Now, these new fields will be sent in all events.
// 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 comment
The reason will be displayed to describe this comment to others. Learn more.
This will pass if room.t === undefined
, I'd suggest this:
if (room.t !== 'l' || room.v == null || room.v.token == null)) {
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.
@rodrigok, fix was done according to suggestion.
This code is a copy from sendToFacebook.js and sendMessageBySMS.js, maybe these callbacks need the same changes.
|
||
sendToCRM('Message', room, [message]); | ||
return message; | ||
}, RocketChat.callbacks.priority.MEDIUM, 'sendMessageToFacebook'); |
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.
The callback ID/name is wrong sendMessageToFacebook
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.
@rodrigok, fixed callback ID to livechat-send-crm-message
@RocketChat/core
This PR added a new event to notifiy using livechat webhook (CRM url).
The new events are:
The payloads used here are the same for the other webhook events (https://rocket.chat/docs/administrator-guides/livechat/#integrations)
The "messages" attribute will contains only the last message.
Screenshot with these new webhook events options: