Chore: Add Facebook app set up documentation (#647)

Co-authored-by: Pranav Raj S <pranavrajs@gmail.com>
This commit is contained in:
Sojan Jose
2020-03-28 11:43:02 +05:30
committed by GitHub
parent 209e0a0fb4
commit a3c2d4e5bd
23 changed files with 211 additions and 38 deletions

View File

@@ -59,6 +59,8 @@ class Api::V1::Accounts::CallbacksController < Api::BaseController
def long_lived_token(omniauth_token)
koala = Koala::Facebook::OAuth.new(ENV['FB_APP_ID'], ENV['FB_APP_SECRET'])
koala.exchange_access_token_info(omniauth_token)['access_token']
rescue StandardError => e
Rails.logger e
end
def mark_already_existing_facebook_pages(data)

View File

@@ -3,7 +3,7 @@ import ApiClient from '../ApiClient';
class FBChannel extends ApiClient {
constructor() {
super('facebook_indicators');
super('facebook_indicators', { accountScoped: true });
}
markSeen({ inboxId, contactId }) {
@@ -22,7 +22,7 @@ class FBChannel extends ApiClient {
create(params) {
return axios.post(
`${this.apiVersion}/callbacks/register_facebook_page`,
`${this.url.replace(this.resource, '')}callbacks/register_facebook_page`,
params
);
}

View File

@@ -5,9 +5,9 @@
import endPoints from './endPoints';
export default {
fetchFacebookPages(token) {
fetchFacebookPages(token, accountId) {
const urlData = endPoints('fetchFacebookPages');
urlData.params.omniauth_token = token;
return axios.post(urlData.url, urlData.params);
return axios.post(urlData.url(accountId), urlData.params);
},
};

View File

@@ -28,7 +28,9 @@ const endPoints = {
},
fetchFacebookPages: {
url: 'api/v1/callbacks/facebook_pages.json',
url(accountId) {
return `api/v1/accounts/${accountId}/callbacks/facebook_pages.json`;
},
params: { omniauth_token: '' },
},

View File

@@ -0,0 +1,15 @@
import fbChannel from '../../channel/fbChannel';
import ApiClient from '../../ApiClient';
describe('#FBChannel', () => {
it('creates correct instance', () => {
expect(fbChannel).toBeInstanceOf(ApiClient);
expect(fbChannel).toHaveProperty('get');
expect(fbChannel).toHaveProperty('show');
expect(fbChannel).toHaveProperty('create');
expect(fbChannel).toHaveProperty('update');
expect(fbChannel).toHaveProperty('delete');
expect(fbChannel).toHaveProperty('markSeen');
expect(fbChannel).toHaveProperty('toggleTyping');
});
});

View File

@@ -68,6 +68,7 @@
/* global FB */
import { required } from 'vuelidate/lib/validators';
import LoadingState from 'dashboard/components/widgets/LoadingState';
import { mapGetters } from 'vuex';
import ChannelApi from '../../../../../api/channels';
import PageHeader from '../../SettingsSubPageHeader';
import router from '../../../../index';
@@ -111,6 +112,12 @@ export default {
getSelectablePages() {
return this.pageList.filter(item => !item.exists);
},
...mapGetters({
currentUser: 'getCurrentUser',
}),
accountId() {
return this.currentUser.account_id;
},
},
created() {
@@ -194,13 +201,20 @@ export default {
);
},
fetchPages(_token) {
ChannelApi.fetchFacebookPages(_token)
.then(response => {
this.pageList = response.data.data.page_details;
this.user_access_token = response.data.data.user_access_token;
})
.catch();
async fetchPages(_token) {
try {
const response = await ChannelApi.fetchFacebookPages(
_token,
this.accountId
);
const {
data: { data },
} = response;
this.pageList = data.page_details;
this.user_access_token = data.user_access_token;
} catch (error) {
// Ignore error
}
},
channelParams() {

View File

@@ -30,6 +30,18 @@ class Attachment < ApplicationRecord
base_data.merge(file_metadata)
end
def file_url
file.attached? ? url_for(file) : ''
end
def thumb_url
if file.attached? && file.representable?
url_for(file.representation(resize: '250x250'))
else
''
end
end
private
def file_metadata
@@ -64,16 +76,4 @@ class Attachment < ApplicationRecord
account_id: account_id
}
end
def file_url
file.attached? ? url_for(file) : ''
end
def thumb_url
if file.attached? && file.representable?
url_for(file.representation(resize: '250x250'))
else
''
end
end
end

View File

@@ -32,13 +32,35 @@ class Facebook::SendReplyService
# end
# end
def fb_message_params
def fb_text_message_params
{
recipient: { id: contact.get_source_id(inbox.id) },
message: { text: message.content }
}
end
def fb_attachment_message_params
{
recipient: { id: contact.get_source_id(inbox.id) },
message: {
attachment: {
type: 'image',
payload: {
url: message.attachment.file_url
}
}
}
}
end
def fb_message_params
if message.attachment.blank?
fb_text_message_params
else
fb_attachment_message_params
end
end
def delivery_params
if twenty_four_hour_window_over?
fb_message_params.merge(tag: 'ISSUE_RESOLUTION')