communicate_twitter.rb 1012 B

123456789101112131415161718192021222324252627282930313233
  1. # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
  2. class Observer::Ticket::Article::CommunicateTwitter < ActiveRecord::Observer
  3. observe 'ticket::_article'
  4. def after_create(record)
  5. # return if we run import mode
  6. return if Setting.get('import_mode')
  7. # if sender is customer, do not communication
  8. sender = Ticket::Article::Sender.lookup( :id => record.sender_id )
  9. return 1 if sender == nil
  10. return 1 if sender['name'] == 'Customer'
  11. # only apply on tweets
  12. type = Ticket::Article::Type.lookup( :id => record.type_id )
  13. return if type['name'] != 'twitter direct-message' && type['name'] != 'twitter status'
  14. a = Channel::Twitter2.new
  15. message = a.send(
  16. {
  17. :type => type['name'],
  18. :to => record.to,
  19. :body => record.body,
  20. :in_reply_to => record.in_reply_to
  21. },
  22. # Rails.application.config.channel_twitter
  23. )
  24. record.message_id = message.id
  25. record.save
  26. end
  27. end