Skip to content

Commit

Permalink
Smarti-52: Add support for edited messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Peyman Aparviz committed Mar 20, 2018
1 parent 6d4e27f commit 76be1dc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ import { getKnowledgeAdapter } from '../lib/KnowledgeAdapterProvider';
RocketChat.callbacks.remove('afterSaveMessage', 'externalWebHook');

RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
// skips this callback if the message was edited
if (message.editedAt) {
return message;
}

let knowledgeEnabled = false;
RocketChat.settings.get('Assistify_AI_Enabled', function(key, value) {
knowledgeEnabled = value;
Expand Down
17 changes: 15 additions & 2 deletions packages/assistify-ai/server/lib/SmartiAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,21 @@ export class SmartiAdapter {

if (conversationId) {
SystemLogger.debug(`Conversation ${ conversationId } found for channel ${ message.rid }`);
// add message to conversation
SmartiProxy.propagateToSmarti(verbs.post, `conversation/${ conversationId }/message`, requestBodyMessage);
if (message.editedAt) {
SystemLogger.debug('Trying to update existing message...');
// update existing message
SmartiProxy.propagateToSmarti(verbs.put, `conversation/${ conversationId }/message/${ requestBodyMessage.id }`, requestBodyMessage, (error) => {
// 404 is expected if message doesn't exist
if (error.response.statusCode === 404) {
SystemLogger.debug('Message not found!');
return null;
}
});
} else {
SystemLogger.debug('Adding new message to conversation...');
// add message to conversation
SmartiProxy.propagateToSmarti(verbs.post, `conversation/${ conversationId }/message`, requestBodyMessage);
}
} else {
SystemLogger.debug('Conversation not found for channel');
const helpRequest = RocketChat.models.HelpRequests.findOneByRoomId(message.rid);
Expand Down

0 comments on commit 76be1dc

Please sign in to comment.