Skip to content
Snippets Groups Projects
Commit 2a424a72 authored by Gabriel Engel's avatar Gabriel Engel Committed by GitHub
Browse files

Merge pull request #6298 from RocketChat/google-natural-language-integration

POC Google Natural Language integration
parents c732a803 c49bb311
No related branches found
No related tags found
No related merge requests found
Showing
with 1862 additions and 1 deletion
......@@ -169,3 +169,4 @@ underscorestring:underscore.string
yasaricli:slugify
yasinuslu:blaze-meta
deepwell:bootstrap-datepicker2
rocketchat:google-natural-language
......@@ -146,6 +146,7 @@ rocketchat:file@0.0.1
rocketchat:file-upload@0.0.1
rocketchat:github-enterprise@0.0.1
rocketchat:gitlab@0.0.1
rocketchat:google-natural-language@0.0.1
rocketchat:highlight-words@0.0.1
rocketchat:i18n@0.0.1
rocketchat:iframe-login@1.0.0
......
node_modules
This directory and the files immediately inside it are automatically generated
when you change this package's NPM dependencies. Commit the files in this
directory (npm-shrinkwrap.json, .gitignore, and this README) to source control
so that others run the same versions of sub-dependencies.
You should NOT check in the node_modules directory that Meteor automatically
creates; if you are using git, the .gitignore file tells git to ignore it.
This diff is collapsed.
Template.room.helpers({
sentimentSmile() {
if (!RocketChat.settings.get('GoogleNaturalLanguage_Enabled')) {
return;
}
const room = ChatRoom.findOne(this._id, { fields: { sentiment: 1 } });
if (room.sentiment >= 0.3) {
return ':)';
} else if (room.sentiment >= -0.3) {
return ':|';
} else if (room.sentiment < -0.3) {
return ':(';
}
}
});
Package.describe({
name: 'rocketchat:google-natural-language',
version: '0.0.1',
summary: 'Rocket.Chat Google Natural Language integration',
git: ''
});
Npm.depends({
'@google-cloud/language': '0.8.0'
});
Package.onUse(function(api) {
api.use('ecmascript');
api.use('http');
api.use('templating', 'client');
api.use('rocketchat:lib');
api.use('rocketchat:ui', 'client');
api.mainModule('client/index.js', 'client');
api.mainModule('server/index.js', 'server');
});
import './settings.js';
import './models/Rooms.js';
const googleLanguage = Npm.require('@google-cloud/language');
let languageClient;
RocketChat.settings.get('GoogleNaturalLanguage_ServiceAccount', (key, value) => {
if (value) {
try {
languageClient = googleLanguage({
credentials: JSON.parse(value)
});
} catch (e) {
languageClient = null;
console.error('Error parsing Google Natural Language credential.', e);
}
}
});
const setRoomSentiment = function(message) {
if (!languageClient) {
return;
}
languageClient.detectSentiment(message.msg, Meteor.bindEnvironment((error, result) => {
if (!error) {
RocketChat.models.Rooms.setSentiment(message.rid, result);
}
}));
return message;
};
RocketChat.settings.get('GoogleNaturalLanguage_Enabled', (key, value) => {
if (value) {
RocketChat.callbacks.add('afterSaveMessage', setRoomSentiment, RocketChat.callbacks.priority.MEDIUM, 'GoogleNaturalLanguage');
} else {
RocketChat.callbacks.remove('afterSaveMessage', 'GoogleNaturalLanguage');
}
});
RocketChat.models.Rooms.setSentiment = function(roomId, sentiment) {
return this.update({ _id: roomId }, { $set: { sentiment } });
};
Meteor.startup(function() {
RocketChat.settings.add('GoogleNaturalLanguage_Enabled', false, {
type: 'boolean',
group: 'Message',
section: 'Google Natural Language',
public: true,
i18nLabel: 'Enabled'
});
RocketChat.settings.add('GoogleNaturalLanguage_ServiceAccount', '', {
type: 'string',
group: 'Message',
section: 'Google Natural Language',
multiline: true,
enableQuery: {
_id: 'GoogleNaturalLanguage_Enabled',
value: true
},
i18nLabel: 'Service_account_key'
});
});
......@@ -622,6 +622,7 @@
"Give_the_application_a_name_This_will_be_seen_by_your_users": "Give the application a name. This will be seen by your users.",
"Global": "Global",
"GoogleCloudStorage": "Google Cloud Storage",
"GoogleNaturalLanguage_ServiceAccount_Description": "Service account key JSON file. More information can be found [here](https://cloud.google.com/natural-language/docs/common/auth#set_up_a_service_account)",
"GoogleTagManager_id": "Google Tag Manager Id",
"Guest_Pool": "Guest Pool",
"Hash": "Hash",
......@@ -1330,6 +1331,7 @@
"Sending": "Sending...",
"Served_By": "Served By",
"Service": "Service",
"Service_account_key": "Service account key",
"Set_as_moderator": "Set as moderator",
"Set_as_owner": "Set as owner",
"Settings": "Settings",
......
......@@ -19,6 +19,9 @@
{{#if secondaryName}}
<span class="secondary-name">@{{secondaryName}}</span>
{{/if}}
{{#if sentimentSmile}}
<span class="sentiment">{{sentimentSmile}}</span>
{{/if}}
{{#if isTranslated}}
<i class="icon-language" aria-label="{{_ "Translated"}}"></i>
{{/if}}
......
......@@ -22,7 +22,8 @@ const options = {
open: 1,
v: 1,
label: 1,
ro: 1
ro: 1,
sentiment: 1
}
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment