lita-zendesk 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: aabcb090fad104d0024bfe14e712a4ce1b30d282
4
+ data.tar.gz: 89ca54dd607cce659d128858cce85d77dd37dc1e
5
+ SHA512:
6
+ metadata.gz: 03f256f0deb9b2c51af2556a5f8c45811508dec432bfa7668ecb7b43754c2e0f33499cc751af9bdd8072aafa6f74b96de3e6a1cc6b7dad2428fb59fad45178ca
7
+ data.tar.gz: 4f00ff67c9dfe987609efc84407f5a048437948c3a8b1b6bce73019a2088c8e2fa951675659c3a5087e7b70a57025cf9d16080ed7e761ce3abe33817bbec1682
@@ -0,0 +1,7 @@
1
+ require 'lita'
2
+
3
+ Lita.load_locales Dir[File.expand_path(
4
+ File.join('..', '..', 'locales', '*.yml'), __FILE__
5
+ )]
6
+
7
+ require 'lita/handlers/zendesk'
@@ -0,0 +1,181 @@
1
+ require 'base64'
2
+ require 'faraday'
3
+ require 'faraday_middleware'
4
+ require 'pp'
5
+
6
+ module Lita
7
+ module Handlers
8
+ class Zendesk < Handler
9
+ is_command = false
10
+
11
+ VERSION_URL = 'api/v2'
12
+ QUERY_TICKETS_ALL = 'tickets'
13
+ QUERY_TICKETS_ESCALATED = 'search.json?query=tags:escalated+status:open+status:pending+type:ticket'
14
+ QUERY_TICKETS_HOLD = 'search.json?query=status:hold+type:ticket'
15
+ QUERY_TICKETS_OPEN = 'search.json?query=status:open+type:ticket'
16
+ QUERY_TICKETS_NEW = 'search.json?query=status:new+type:ticket'
17
+ QUERY_TICKETS_PENDING = 'search.json?query=status:pending+type:ticket'
18
+ QUERY_TICKETS_UNSOLVED = 'search.json?query=status<solved+type:ticket'
19
+ QUERY_USERS = 'users'
20
+
21
+ config :subdomain, type: String, required: true
22
+ config :auth_type, type: String, default: 'password' # or token
23
+ config :user, type: String, required: true
24
+ config :token, type: String, default: ''
25
+ config :password, type: String, default: ''
26
+
27
+ def init
28
+ @base_url = "https://#{config.subdomain.to_s}.zendesk.com"
29
+ @version_url = "https://#{config.subdomain.to_s}.zendesk.com/#{VERSION_URL}"
30
+ @tickets_url = "https://#{config.subdomain.to_s}.zendesk.com/tickets"
31
+
32
+ if config.auth_type == 'password'
33
+ @conn = Faraday.new(url: @version_url) do |faraday|
34
+ faraday.headers['Authorization'] = "Basic #{basic_credentials}"
35
+ faraday.response :json # JSON response
36
+ faraday.response :logger # log requests to STDOUT
37
+ faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
38
+ end
39
+ else
40
+ @conn = Faraday.new(url: @version_url) do |faraday|
41
+ faraday.response :json # JSON response
42
+ faraday.response :logger # log requests to STDOUT
43
+ faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
44
+ end
45
+ @conn.basic_auth("#{config.user}/token", config.token)
46
+ end
47
+ end
48
+
49
+ def basic_credentials
50
+ Base64.encode64("#{config.user}:#{config.password}").gsub(/\s/,'')
51
+ end
52
+
53
+ def zendesk_request(url)
54
+ init unless @conn
55
+ if url.index('http') != 0
56
+ url = "#{@version_url}/#{url}"
57
+ end
58
+ @conn.get url
59
+ end
60
+
61
+ def ticket_count(response, url, ticket_type = '')
62
+ res = zendesk_request url
63
+ ticket_count = res.body['count']
64
+ ticket_word = ticket_count == 1 ? 'ticket' : 'tickets'
65
+ ticket_desc = ticket_type == '' ? '' : "#{ticket_type} "
66
+ response.reply "#{ticket_count} #{ticket_desc}#{ticket_word}."
67
+ end
68
+
69
+ def ticket_list(response, url, ticket_type = '')
70
+ res = zendesk_request url
71
+ tickets = res.body['results']
72
+ tickets.each do |ticket|
73
+ response.reply "Ticket #{ticket['id']} is #{ticket['status']}: #{@tickets_url}/#{ticket['id']} - #{ticket['subject']}"
74
+ end
75
+ ticket_length = tickets.length
76
+ ticket_count = res.body['count']
77
+ ticket_word = ticket_count == 1 ? 'ticket' : 'tickets'
78
+ ticket_desc = ticket_type == '' ? '' : "#{ticket_type} "
79
+ response.reply "Listing #{ticket_length} of #{ticket_count} #{ticket_desc}#{ticket_word}."
80
+ end
81
+
82
+ def tickets(count)
83
+ count == 1 ? 'ticket' : 'tickets'
84
+ end
85
+
86
+ # Ticket Counts
87
+
88
+ route(/^(?:zd|zendesk)(\s+unsolved)?\s+tickets?\s*$/, :unsolved_tickets, command: true, help: { 'zd tickets' => 'returns the total count of all unsolved tickets' })
89
+ def unsolved_tickets(response)
90
+ ticket_count response, QUERY_TICKETS_UNSOLVED, 'unsolved'
91
+ end
92
+
93
+ route(/^(?:zd|zendesk)\s+(all|total)\s+tickets?\s*$/, :total_tickets, command: true, help: { 'zd all tickets' => 'returns the count of all tickets' })
94
+ def total_tickets(response)
95
+ ticket_count response, QUERY_TICKETS_ALL, 'total'
96
+ end
97
+
98
+ route(/^(?:zd|zendesk)\s+pending\s+tickets?\s*$/, :pending_tickets, command: true, help: { 'zd pending tickets' => 'returns a count of tickets that are pending' })
99
+ def pending_tickets(response)
100
+ ticket_count response, QUERY_TICKETS_PENDING, 'pending'
101
+ end
102
+
103
+ route(/^(?:zd|zendesk)\s+new\s+tickets?\s*$/, :new_tickets, command: true, help: { 'zd new tickets' => 'returns the count of all new (unassigned) tickets' })
104
+ def new_tickets(response)
105
+ ticket_count response, QUERY_TICKETS_NEW, 'new'
106
+ end
107
+
108
+ route(/^(?:zd|zendesk)\s+escalated\s+tickets?\s*$/, :escalated_tickets, command: true, help: { 'zd escalated tickets' => 'returns a count of tickets with escalated tag that are open or pending' })
109
+ def escalated_tickets(response)
110
+ ticket_count response, QUERY_TICKETS_ESCALATED, 'escalated'
111
+ end
112
+
113
+ route(/^(?:zd|zendesk)\s+open\s+tickets?\s*$/, :open_tickets, command: true, help: { 'zd open tickets' => 'returns the count of all open tickets' })
114
+ def open_tickets(response)
115
+ ticket_count response, QUERY_TICKETS_OPEN, 'open'
116
+ end
117
+
118
+ route(/^(?:zd|zendesk)\s+on\s+hold\s+tickets?\s*$/, :onhold_tickets, command: true, help: { 'zd on hold tickets' => 'returns the count of all on hold tickets' })
119
+ def onhold_tickets(response)
120
+ ticket_count response, QUERY_TICKETS_HOLD, 'on hold'
121
+ end
122
+
123
+ # Ticket Lists
124
+
125
+ route(/^(?:zd|zendesk)\s+list(\s+unsolved)?\s+tickets?\s*$/, :unsolved_tickets_list, command: true, help: { 'zd list tickets' => 'returns a list of unsolved tickets' })
126
+ def unsolved_tickets_list(response)
127
+ ticket_list response, QUERY_TICKETS_UNSOLVED, 'unsolved'
128
+ end
129
+
130
+ route(/^(?:zd|zendesk)\s+list\s+(all|total)\s+tickets?\s*$/, :total_tickets_list, command: true, help: { 'zd list all tickets' => 'returns a list of all tickets' })
131
+ def total_tickets_list(response)
132
+ ticket_list response, QUERY_TICKETS_ALL, 'total'
133
+ end
134
+
135
+ route(/^(?:zd|zendesk)\s+list\s+pending\s+tickets?\s*$/, :pending_tickets_list, command: true, help: { 'zd list pending tickets' => 'returns a list of pending tickets' })
136
+ def pending_tickets_list(response)
137
+ ticket_list response, QUERY_TICKETS_PENDING, 'pending'
138
+ end
139
+
140
+ route(/^(?:zd|zendesk)\s+list\s+new\s+tickets?\s*$/, :new_tickets_list, command: true, help: { 'zd list new tickets' => 'returns a list of new tickets' })
141
+ def new_tickets_list(response)
142
+ ticket_list response, QUERY_TICKETS_NEW, 'new'
143
+ end
144
+
145
+ route(/^(?:zd|zendesk)\s+list\s+escalated\s+tickets?\s*$/, :escalated_tickets_list, command: true, help: { 'zd list esclated tickets' => 'returns a list of escalated tickets' })
146
+ def escalated_tickets_list(response)
147
+ ticket_list response, QUERY_TICKETS_ESCALATED, 'escalated'
148
+ end
149
+
150
+ route(/^(?:zd|zendesk)\s+list\s+open\s+tickets?\s*$/, :open_tickets_list, command: true, help: { 'zd list open tickets' => 'returns a list of open tickets' })
151
+ def open_tickets_list(response)
152
+ ticket_list response, QUERY_TICKETS_OPEN, 'open'
153
+ end
154
+
155
+ route(/^(?:zd|zendesk)\s+list\s+on\s+hold\s+tickets?\s*$/, :onhold_tickets_list, command: true, help: { 'zd list onhold tickets' => 'returns a list of on hold tickets' })
156
+ def onhold_tickets_list(response)
157
+ ticket_list response, QUERY_TICKETS_HOLD, 'on hold'
158
+ end
159
+
160
+ # Ticket Details
161
+
162
+ route(/^(?:zd|zendesk)\s+ticket\s+(\d+)\s*$/, :ticket_details, command: true, help: { 'zd ticket <ID>' => 'returns information about the specified ticket' })
163
+ def ticket_details(response)
164
+ ticket_id = response.matches[0][0]
165
+ url = "#{QUERY_TICKETS_ALL}/#{ticket_id}.json"
166
+ res = zendesk_request url
167
+ data = res.body
168
+
169
+ message = "Ticket #{data['ticket']['id']}: #{@tickets_url}/#{data['ticket']['id']}"
170
+ message += "\nStatus: #{data['ticket']['status'].upcase}"
171
+ message += "\nUpdated: " + data['ticket']['updated_at']
172
+ message += "\nAdded: #{data['ticket']['created_at']}"
173
+ message += "\nSubject: #{data['ticket']['subject']}"
174
+ message += "\nDescription:\n-----\n#{data['ticket']['description']}\n-----\n"
175
+ response.reply message
176
+ end
177
+ end
178
+
179
+ Lita.register_handler(Zendesk)
180
+ end
181
+ end
metadata ADDED
@@ -0,0 +1,173 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lita-zendesk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - John Wang
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-08-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: lita
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 4.4.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 4.4.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: ringcentral_sdk
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rack-test
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: 3.0.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: 3.0.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: 0.9.2
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: 0.9.2
125
+ - !ruby/object:Gem::Dependency
126
+ name: coveralls
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: A Zendesk handler for Lita.
140
+ email:
141
+ - johncwang@gmail.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - lib/lita-zendesk.rb
147
+ - lib/lita/handlers/zendesk.rb
148
+ homepage: https://github.com/grokify/lita-zendesk
149
+ licenses:
150
+ - MIT
151
+ metadata:
152
+ lita_plugin_type: handler
153
+ post_install_message:
154
+ rdoc_options: []
155
+ require_paths:
156
+ - lib
157
+ required_ruby_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ required_rubygems_version: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ requirements: []
168
+ rubyforge_project:
169
+ rubygems_version: 2.5.1
170
+ signing_key:
171
+ specification_version: 4
172
+ summary: A Zendesk handler for the Lita chat robot.
173
+ test_files: []