Commit 02d4148bd74e23c9cc4b1d81c1116d7e306a8cdb
1 parent
85190d80
Exists in
master
and in
1 other branch
added support for any jabber and ability to send to rooms
Showing
1 changed file
with
41 additions
and
8 deletions
Show diff stats
app/models/notification_services/gtalk_service.rb
| @@ -9,31 +9,64 @@ class NotificationServices::GtalkService < NotificationService | @@ -9,31 +9,64 @@ class NotificationServices::GtalkService < NotificationService | ||
| 9 | :placeholder => "password", | 9 | :placeholder => "password", |
| 10 | :label => "Password" | 10 | :label => "Password" |
| 11 | }], | 11 | }], |
| 12 | + [:user_id, { | ||
| 13 | + :placeholder => "touser@example.com, anotheruser@example.com", | ||
| 14 | + :label => "Send To User(s)" | ||
| 15 | + }, :room_id], | ||
| 12 | [:room_id, { | 16 | [:room_id, { |
| 13 | - :placeholder => "touser@example.com, anotheruser@example.com", | ||
| 14 | - :label => "Send To User(s)" | 17 | + :placeholder => "toroom@conference.example.com", |
| 18 | + :label => "Send To Room (one only)" | ||
| 19 | + }, :user_id], | ||
| 20 | + [ :service, { | ||
| 21 | + :placeholder => "talk.google.com", | ||
| 22 | + :label => "Jabber Service" | ||
| 15 | }], | 23 | }], |
| 24 | + [ :service_url, { | ||
| 25 | + :placeholder => "http://www.google.com/talk/", | ||
| 26 | + :label => "Link To Jabber Service" | ||
| 27 | + }] | ||
| 16 | ] | 28 | ] |
| 17 | 29 | ||
| 18 | def check_params | 30 | def check_params |
| 19 | - if Fields.detect {|f| self[f[0]].blank? } | ||
| 20 | - errors.add :base, 'You must specify your Username, Password and To User(s)' | 31 | + if Fields.detect { |f| self[f[0]].blank? && self[f[2]].blank? } |
| 32 | + errors.add :base, | ||
| 33 | + """You must specify your Username, Password, service, service_url | ||
| 34 | + and either rooms or users to send to or both""" | ||
| 21 | end | 35 | end |
| 22 | end | 36 | end |
| 23 | 37 | ||
| 24 | def url | 38 | def url |
| 25 | - "http://www.google.com/talk/" | 39 | + "http://www.google.com/talk/" || service_url |
| 26 | end | 40 | end |
| 27 | 41 | ||
| 28 | def create_notification(problem) | 42 | def create_notification(problem) |
| 29 | # build the xmpp client | 43 | # build the xmpp client |
| 30 | client = Jabber::Client.new(Jabber::JID.new(subdomain)) | 44 | client = Jabber::Client.new(Jabber::JID.new(subdomain)) |
| 31 | - client.connect("talk.google.com") | 45 | + client.connect(service) |
| 32 | client.auth(api_token) | 46 | client.auth(api_token) |
| 33 | 47 | ||
| 48 | + #has to look like this to be formatted properly in the client | ||
| 49 | + message = """#{problem.app.name.to_s} | ||
| 50 | +http://#{Errbit::Config.host}/apps/#{problem.app.id.to_s} | ||
| 51 | +#{notification_description problem}""" | ||
| 52 | + | ||
| 34 | # post the issue to the xmpp room(s) | 53 | # post the issue to the xmpp room(s) |
| 35 | - room_id.gsub(/ /i, ",").gsub(/;/i, ",").split(",").map(&:strip).reject(&:empty?).each do |room| | ||
| 36 | - client.send(Jabber::Message.new(room, "[errbit] http://#{Errbit::Config.host}/apps/#{problem.app.id.to_s} #{notification_description problem}")) | 54 | + send_to_users(client, message) unless user_id.blank? |
| 55 | + send_to_muc(client, message) unless room_id.blank? | ||
| 56 | + end | ||
| 57 | + | ||
| 58 | + private | ||
| 59 | + | ||
| 60 | + def send_to_users client, message | ||
| 61 | + user_id.gsub(/ /i, ",").gsub(/;/i, ",").split(",").map(&:strip).reject(&:empty?).each do |user| | ||
| 62 | + client.send(Jabber::Message.new(user, message)) | ||
| 37 | end | 63 | end |
| 38 | end | 64 | end |
| 65 | + | ||
| 66 | + def send_to_muc client, message | ||
| 67 | + #TODO: set this so that it can send to multiple rooms like users, nb multiple room joins in one send fail randomly so leave as one room for the moment | ||
| 68 | + muc = Jabber::MUC::SimpleMUCClient.new(client) | ||
| 69 | + muc.join(room_id + "/errbit") | ||
| 70 | + muc.send(Jabber::Message.new(room_id, message)) | ||
| 71 | + end | ||
| 39 | end | 72 | end |