@@ -71,8 +69,10 @@
<%- @Icon(@article.type.name, 'article-meta-icon') %>
<%- @T(@article.type.name) %>
- <% if @article.type.name is 'email': %>
-
<%- @T('raw') %>
+ <% if @article.preferences.links: %>
+ <% for item in @article.preferences.links: %>
+
<%- @T(item.name) %>
+ <% end %>
<% end %>
diff --git a/app/models/channel/driver/facebook.rb b/app/models/channel/driver/facebook.rb
index 9fe8b50dd..62320b31d 100644
--- a/app/models/channel/driver/facebook.rb
+++ b/app/models/channel/driver/facebook.rb
@@ -86,7 +86,7 @@ class Channel::Driver::Facebook
next if page_to_sync_params['group_id'].empty?
page_client = Facebook.new(page['access_token'])
- posts = page_client.client.get_connection('me', 'feed', fields: 'id,from,to,message,created_time,comments')
+ posts = page_client.client.get_connection('me', 'feed', fields: 'id,from,to,message,created_time,permalink_url,comments{id,from,to,message,created_time}')
posts.each { |post|
# ignore older messages
diff --git a/lib/facebook.rb b/lib/facebook.rb
index 4793ca4f9..bded96b63 100644
--- a/lib/facebook.rb
+++ b/lib/facebook.rb
@@ -210,8 +210,7 @@ result
end
state = get_state(page, post)
-
- Ticket.create(
+ Ticket.create!(
customer_id: user.id,
title: title,
group_id: group_id,
@@ -220,6 +219,9 @@ result
preferences: {
channel_id: channel.id,
channel_fb_object_id: page['id'],
+ facebook: {
+ permalink_url: post['permalink_url'],
+ }
},
)
end
@@ -260,6 +262,11 @@ result
articles += nested_comments(post['comments']['data'], post['id'])
end
+ base_url = nil
+ if ticket.preferences['facebook'] && ticket.preferences['facebook']['permalink_url']
+ base_url = ticket.preferences['facebook']['permalink_url']
+ end
+
articles.each { |article|
next if Ticket::Article.find_by(message_id: article[:message_id])
@@ -270,6 +277,22 @@ result
ticket.save!
end
+ links = []
+ if base_url
+ url = base_url
+ realtive_id = article[:message_id].split('_')[1]
+ if realtive_id
+ url += "?comment_id=#{realtive_id}"
+ end
+ links = [
+ {
+ url: url,
+ target: '_blank',
+ name: 'on Facebook',
+ },
+ ]
+ end
+
article = {
#to: @account['name'],
ticket_id: ticket.id,
@@ -277,6 +300,9 @@ result
sender_id: Ticket::Article::Sender.lookup(name: 'Customer').id,
created_by_id: 1,
updated_by_id: 1,
+ preferences: {
+ links: links,
+ },
}.merge(article)
Ticket::Article.create(article)
}
@@ -363,7 +389,7 @@ result
in_reply_to: in_reply_to
}
result.push(article_data)
- sub_comments = @client.get_object("#{comment['id']}/comments")
+ sub_comments = @client.get_object("#{comment['id']}/comments", fields: 'id,from,to,message,created_time')
sub_articles = nested_comments(sub_comments, comment['id'])
result += sub_articles
}
diff --git a/lib/tweet_base.rb b/lib/tweet_base.rb
index 8b7b32ead..d7677065b 100644
--- a/lib/tweet_base.rb
+++ b/lib/tweet_base.rb
@@ -208,7 +208,7 @@ class TweetBase
ticket.save!
end
- Ticket::Article.create(
+ Ticket::Article.create!(
from: from,
to: to,
body: tweet.text,