Skip to content

Commit

Permalink
Merge pull request #9365 from RocketChat/improve-livechat-facebook-in…
Browse files Browse the repository at this point in the history
…tegration-flow

[FIX] Force enable Livechat Facebook integration on specific errors
  • Loading branch information
rodrigok authored Jan 18, 2018
2 parents 54d09e7 + 29e5fc6 commit ad8daf9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ Template.livechatIntegrationFacebook.onCreated(function() {

this.result = (successFn, errorFn = () => {}) => {
return (error, result) => {
// fix the state where user it was enabled on admin
if (error && error.error) {
switch (error.error) {
case 'invalid-facebook-token':
case 'invalid-instance-url':
case 'integration-disabled':
return Meteor.call('livechat:facebook', { action: 'enable' }, this.result(() => {
this.enabled.set(true);
this.loadPages();
}, () => this.loadPages()));
}
}

if (result && result.success === false && (result.type === 'OAuthException' || typeof result.url !== 'undefined')) {
const oauthWindow = window.open(result.url, 'facebook-integration-oauth', 'width=600,height=400');

Expand Down
15 changes: 10 additions & 5 deletions packages/rocketchat-livechat/server/methods/facebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,16 @@ Meteor.methods({
}
}
} catch (e) {
if (e.response && e.response.data && e.response.data.error && e.response.data.error.response) {
throw new Meteor.Error('integration-error', e.response.data.error.response.error.message);
}
if (e.response && e.response.data && e.response.data.error && e.response.data.error.message) {
throw new Meteor.Error('integration-error', e.response.data.error.message);
if (e.response && e.response.data && e.response.data.error) {
if (e.response.data.error.error) {
throw new Meteor.Error(e.response.data.error.error, e.response.data.error.message);
}
if (e.response.data.error.response) {
throw new Meteor.Error('integration-error', e.response.data.error.response.error.message);
}
if (e.response.data.error.message) {
throw new Meteor.Error('integration-error', e.response.data.error.message);
}
}
console.error('Error contacting omni.rocket.chat:', e);
throw new Meteor.Error('integration-error', e.error);
Expand Down

0 comments on commit ad8daf9

Please sign in to comment.