trabajo-afectivo/app/models/observer/ticket/article/communicate_twitter.rb

34 lines
1.1 KiB
Ruby
Raw Normal View History

2014-02-03 19:23:00 +00:00
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
2015-07-02 15:13:04 +00:00
# http://stem.ps/rails/2015/01/25/ruby-gotcha-toplevel-constant-referenced-by.html
require 'channel/twitter'
class Observer::Ticket::Article::CommunicateTwitter < ActiveRecord::Observer
observe 'ticket::_article'
def after_create(record)
# return if we run import mode
return if Setting.get('import_mode')
# if sender is customer, do not communication
sender = Ticket::Article::Sender.lookup( id: record.sender_id )
2015-07-02 15:13:04 +00:00
return if sender.nil?
return if sender['name'] == 'Customer'
# only apply on tweets
type = Ticket::Article::Type.lookup( id: record.type_id )
2015-07-02 15:13:04 +00:00
return if type['name'] !~ /\Atwitter/
2015-07-02 15:13:04 +00:00
twitter = Channel::Twitter.new
tweet = twitter.send({
type: type['name'],
2015-07-03 17:21:30 +00:00
to: record.to,
body: record.body,
in_reply_to: record.in_reply_to
})
2015-07-02 15:13:04 +00:00
record.message_id = tweet.id
record.save
end
end