communify 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +211 -41
- data/README.md +93 -81
- data/communify.gemspec +14 -3
- data/lib/communify/controllers/push_notification_controller.rb +16 -15
- data/lib/communify/generators/install/templates/communify_log_model.erb +3 -4
- data/lib/communify/generators/push_notification/push_notification_generator.rb +4 -0
- data/lib/communify/generators/push_notification/templates/fcmpush_initializer.erb +7 -0
- data/lib/communify/version.rb +1 -1
- data/lib/communify/workers/push_notification_worker.rb +67 -35
- metadata +21 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 65b93b3239597b49680b866988faabf27d2f15e188bb3bfac1fe022e64302c56
|
4
|
+
data.tar.gz: cc00629947c50b0301261345cf6d5b307f5d09c73a691b8a53a777e877cbca80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e90c4b30581f00eec103ee07266c6631e75ebb4358974dc0cfee704f2ad425b69363d033da4ae3915b5aedf4f5353cebc596e9b120510c1e1e227f29f33f3f6
|
7
|
+
data.tar.gz: 0e8158afa500f9095c516d05e2426cc6dd8107f13b6f4b1ec85b68949a8921f169c8740f35fcca2c6cb087cdc907b37a6b8e78d55b0a0232a9f32b6b4852cf58
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
@@ -4,3 +4,10 @@ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
|
4
4
|
|
5
5
|
# Specify your gem's dependencies in communify.gemspec
|
6
6
|
gemspec
|
7
|
+
|
8
|
+
group :development, :test do
|
9
|
+
gem 'rails', '~> 6.0'
|
10
|
+
gem 'rspec-rails'
|
11
|
+
gem 'generator_spec'
|
12
|
+
gem 'sidekiq', '~> 6.2', require: 'sidekiq/testing'
|
13
|
+
end
|
data/Gemfile.lock
CHANGED
@@ -1,83 +1,253 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
communify (
|
4
|
+
communify (1.0.0)
|
5
|
+
fcmpush (~> 1.4.4)
|
6
|
+
twilio-ruby (~> 5.69.0)
|
5
7
|
|
6
8
|
GEM
|
7
9
|
remote: https://rubygems.org/
|
8
10
|
specs:
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
actioncable (6.1.4.7)
|
12
|
+
actionpack (= 6.1.4.7)
|
13
|
+
activesupport (= 6.1.4.7)
|
14
|
+
nio4r (~> 2.0)
|
15
|
+
websocket-driver (>= 0.6.1)
|
16
|
+
actionmailbox (6.1.4.7)
|
17
|
+
actionpack (= 6.1.4.7)
|
18
|
+
activejob (= 6.1.4.7)
|
19
|
+
activerecord (= 6.1.4.7)
|
20
|
+
activestorage (= 6.1.4.7)
|
21
|
+
activesupport (= 6.1.4.7)
|
22
|
+
mail (>= 2.7.1)
|
23
|
+
actionmailer (6.1.4.7)
|
24
|
+
actionpack (= 6.1.4.7)
|
25
|
+
actionview (= 6.1.4.7)
|
26
|
+
activejob (= 6.1.4.7)
|
27
|
+
activesupport (= 6.1.4.7)
|
28
|
+
mail (~> 2.5, >= 2.5.4)
|
29
|
+
rails-dom-testing (~> 2.0)
|
30
|
+
actionpack (6.1.4.7)
|
31
|
+
actionview (= 6.1.4.7)
|
32
|
+
activesupport (= 6.1.4.7)
|
33
|
+
rack (~> 2.0, >= 2.0.9)
|
34
|
+
rack-test (>= 0.6.3)
|
35
|
+
rails-dom-testing (~> 2.0)
|
36
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
37
|
+
actiontext (6.1.4.7)
|
38
|
+
actionpack (= 6.1.4.7)
|
39
|
+
activerecord (= 6.1.4.7)
|
40
|
+
activestorage (= 6.1.4.7)
|
41
|
+
activesupport (= 6.1.4.7)
|
42
|
+
nokogiri (>= 1.8.5)
|
43
|
+
actionview (6.1.4.7)
|
44
|
+
activesupport (= 6.1.4.7)
|
45
|
+
builder (~> 3.1)
|
46
|
+
erubi (~> 1.4)
|
47
|
+
rails-dom-testing (~> 2.0)
|
48
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
49
|
+
activejob (6.1.4.7)
|
50
|
+
activesupport (= 6.1.4.7)
|
51
|
+
globalid (>= 0.3.6)
|
52
|
+
activemodel (6.1.4.7)
|
53
|
+
activesupport (= 6.1.4.7)
|
54
|
+
activerecord (6.1.4.7)
|
55
|
+
activemodel (= 6.1.4.7)
|
56
|
+
activesupport (= 6.1.4.7)
|
57
|
+
activestorage (6.1.4.7)
|
58
|
+
actionpack (= 6.1.4.7)
|
59
|
+
activejob (= 6.1.4.7)
|
60
|
+
activerecord (= 6.1.4.7)
|
61
|
+
activesupport (= 6.1.4.7)
|
62
|
+
marcel (~> 1.0.0)
|
63
|
+
mini_mime (>= 1.1.0)
|
64
|
+
activesupport (6.1.4.7)
|
65
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
66
|
+
i18n (>= 1.6, < 2)
|
67
|
+
minitest (>= 5.1)
|
68
|
+
tzinfo (~> 2.0)
|
69
|
+
zeitwerk (~> 2.3)
|
70
|
+
addressable (2.8.7)
|
71
|
+
public_suffix (>= 2.0.2, < 7.0)
|
72
|
+
base64 (0.2.0)
|
73
|
+
builder (3.3.0)
|
74
|
+
concurrent-ruby (1.3.4)
|
75
|
+
connection_pool (2.4.1)
|
76
|
+
crass (1.0.6)
|
77
|
+
date (3.3.4)
|
78
|
+
declarative (0.0.20)
|
79
|
+
diff-lcs (1.5.1)
|
80
|
+
erubi (1.13.0)
|
81
|
+
faraday (2.8.1)
|
82
|
+
base64
|
83
|
+
faraday-net_http (>= 2.0, < 3.1)
|
15
84
|
ruby2_keywords (>= 0.0.4)
|
16
|
-
faraday-net_http (
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
85
|
+
faraday-net_http (3.0.2)
|
86
|
+
fcmpush (1.4.4)
|
87
|
+
google-apis-identitytoolkit_v3
|
88
|
+
net-http-persistent (~> 4.0.1)
|
89
|
+
generator_spec (0.10.0)
|
90
|
+
activesupport (>= 3.0.0)
|
91
|
+
railties (>= 3.0.0)
|
92
|
+
globalid (1.2.1)
|
93
|
+
activesupport (>= 6.1)
|
94
|
+
google-apis-core (0.11.3)
|
95
|
+
addressable (~> 2.5, >= 2.5.1)
|
96
|
+
googleauth (>= 0.16.2, < 2.a)
|
97
|
+
httpclient (>= 2.8.1, < 3.a)
|
98
|
+
mini_mime (~> 1.0)
|
99
|
+
representable (~> 3.0)
|
100
|
+
retriable (>= 2.0, < 4.a)
|
101
|
+
rexml
|
102
|
+
google-apis-identitytoolkit_v3 (0.14.0)
|
103
|
+
google-apis-core (>= 0.11.0, < 2.a)
|
104
|
+
googleauth (1.8.1)
|
21
105
|
faraday (>= 0.17.3, < 3.a)
|
22
106
|
jwt (>= 1.4, < 3.0)
|
23
|
-
memoist (~> 0.16)
|
24
107
|
multi_json (~> 1.11)
|
25
108
|
os (>= 0.9, < 2.0)
|
26
109
|
signet (>= 0.16, < 2.a)
|
27
|
-
|
28
|
-
|
110
|
+
httpclient (2.8.3)
|
111
|
+
i18n (1.14.6)
|
112
|
+
concurrent-ruby (~> 1.0)
|
113
|
+
jwt (2.5.0)
|
114
|
+
loofah (2.22.0)
|
115
|
+
crass (~> 1.0.2)
|
116
|
+
nokogiri (>= 1.12.0)
|
117
|
+
mail (2.8.1)
|
118
|
+
mini_mime (>= 0.1.1)
|
119
|
+
net-imap
|
120
|
+
net-pop
|
121
|
+
net-smtp
|
122
|
+
marcel (1.0.4)
|
123
|
+
method_source (1.1.0)
|
124
|
+
mini_mime (1.1.5)
|
125
|
+
minitest (5.25.1)
|
29
126
|
multi_json (1.15.0)
|
30
|
-
|
127
|
+
net-http-persistent (4.0.4)
|
128
|
+
connection_pool (~> 2.2)
|
129
|
+
net-imap (0.3.7)
|
130
|
+
date
|
131
|
+
net-protocol
|
132
|
+
net-pop (0.1.2)
|
133
|
+
net-protocol
|
134
|
+
net-protocol (0.2.2)
|
135
|
+
timeout
|
136
|
+
net-smtp (0.5.0)
|
137
|
+
net-protocol
|
138
|
+
nio4r (2.7.3)
|
139
|
+
nokogiri (1.13.10-arm64-darwin)
|
140
|
+
racc (~> 1.4)
|
141
|
+
nokogiri (1.13.10-x86_64-linux)
|
31
142
|
racc (~> 1.4)
|
32
143
|
os (1.1.4)
|
33
|
-
public_suffix (5.
|
34
|
-
racc (1.
|
35
|
-
rack (2.2.
|
36
|
-
rack-
|
37
|
-
rack
|
144
|
+
public_suffix (5.1.1)
|
145
|
+
racc (1.8.1)
|
146
|
+
rack (2.2.9)
|
147
|
+
rack-test (2.1.0)
|
148
|
+
rack (>= 1.3)
|
149
|
+
rails (6.1.4.7)
|
150
|
+
actioncable (= 6.1.4.7)
|
151
|
+
actionmailbox (= 6.1.4.7)
|
152
|
+
actionmailer (= 6.1.4.7)
|
153
|
+
actionpack (= 6.1.4.7)
|
154
|
+
actiontext (= 6.1.4.7)
|
155
|
+
actionview (= 6.1.4.7)
|
156
|
+
activejob (= 6.1.4.7)
|
157
|
+
activemodel (= 6.1.4.7)
|
158
|
+
activerecord (= 6.1.4.7)
|
159
|
+
activestorage (= 6.1.4.7)
|
160
|
+
activesupport (= 6.1.4.7)
|
161
|
+
bundler (>= 1.15.0)
|
162
|
+
railties (= 6.1.4.7)
|
163
|
+
sprockets-rails (>= 2.0.0)
|
164
|
+
rails-dom-testing (2.2.0)
|
165
|
+
activesupport (>= 5.0.0)
|
166
|
+
minitest
|
167
|
+
nokogiri (>= 1.6)
|
168
|
+
rails-html-sanitizer (1.5.0)
|
169
|
+
loofah (~> 2.19, >= 2.19.1)
|
170
|
+
railties (6.1.4.7)
|
171
|
+
actionpack (= 6.1.4.7)
|
172
|
+
activesupport (= 6.1.4.7)
|
173
|
+
method_source
|
174
|
+
rake (>= 0.13)
|
175
|
+
thor (~> 1.0)
|
38
176
|
rake (10.5.0)
|
39
177
|
redis (4.7.1)
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
rspec
|
178
|
+
representable (3.2.0)
|
179
|
+
declarative (< 0.1.0)
|
180
|
+
trailblazer-option (>= 0.1.1, < 0.2.0)
|
181
|
+
uber (< 0.2.0)
|
182
|
+
retriable (3.1.2)
|
183
|
+
rexml (3.3.8)
|
184
|
+
rspec (3.13.0)
|
185
|
+
rspec-core (~> 3.13.0)
|
186
|
+
rspec-expectations (~> 3.13.0)
|
187
|
+
rspec-mocks (~> 3.13.0)
|
188
|
+
rspec-core (3.13.1)
|
189
|
+
rspec-support (~> 3.13.0)
|
190
|
+
rspec-expectations (3.13.3)
|
47
191
|
diff-lcs (>= 1.2.0, < 2.0)
|
48
|
-
rspec-support (~> 3.
|
49
|
-
rspec-mocks (3.
|
192
|
+
rspec-support (~> 3.13.0)
|
193
|
+
rspec-mocks (3.13.2)
|
50
194
|
diff-lcs (>= 1.2.0, < 2.0)
|
51
|
-
rspec-support (~> 3.
|
52
|
-
rspec-
|
195
|
+
rspec-support (~> 3.13.0)
|
196
|
+
rspec-rails (6.1.5)
|
197
|
+
actionpack (>= 6.1)
|
198
|
+
activesupport (>= 6.1)
|
199
|
+
railties (>= 6.1)
|
200
|
+
rspec-core (~> 3.13)
|
201
|
+
rspec-expectations (~> 3.13)
|
202
|
+
rspec-mocks (~> 3.13)
|
203
|
+
rspec-support (~> 3.13)
|
204
|
+
rspec-support (3.13.1)
|
53
205
|
ruby2_keywords (0.0.5)
|
54
|
-
sidekiq (6.
|
55
|
-
connection_pool (>= 2.2.
|
206
|
+
sidekiq (6.5.12)
|
207
|
+
connection_pool (>= 2.2.5, < 3)
|
56
208
|
rack (~> 2.0)
|
57
|
-
|
58
|
-
|
59
|
-
signet (0.17.0)
|
209
|
+
redis (>= 4.5.0, < 5)
|
210
|
+
signet (0.18.0)
|
60
211
|
addressable (~> 2.8)
|
61
212
|
faraday (>= 0.17.5, < 3.a)
|
62
213
|
jwt (>= 1.5, < 3.0)
|
63
214
|
multi_json (~> 1.10)
|
215
|
+
sprockets (4.2.1)
|
216
|
+
concurrent-ruby (~> 1.0)
|
217
|
+
rack (>= 2.2.4, < 4)
|
218
|
+
sprockets-rails (3.5.2)
|
219
|
+
actionpack (>= 6.1)
|
220
|
+
activesupport (>= 6.1)
|
221
|
+
sprockets (>= 3.0.0)
|
222
|
+
thor (1.3.2)
|
223
|
+
timeout (0.4.1)
|
224
|
+
trailblazer-option (0.1.2)
|
64
225
|
twilio-ruby (5.69.0)
|
65
226
|
faraday (>= 0.9, < 3.0)
|
66
227
|
jwt (>= 1.5, <= 2.5)
|
67
228
|
nokogiri (>= 1.6, < 2.0)
|
229
|
+
tzinfo (2.0.6)
|
230
|
+
concurrent-ruby (~> 1.0)
|
231
|
+
uber (0.1.0)
|
232
|
+
websocket-driver (0.7.6)
|
233
|
+
websocket-extensions (>= 0.1.0)
|
234
|
+
websocket-extensions (0.1.5)
|
235
|
+
zeitwerk (2.6.18)
|
68
236
|
|
69
237
|
PLATFORMS
|
238
|
+
arm64-darwin-21
|
70
239
|
x86_64-linux
|
71
240
|
|
72
241
|
DEPENDENCIES
|
73
242
|
bundler (~> 2.3)
|
74
243
|
communify!
|
75
|
-
|
244
|
+
generator_spec
|
245
|
+
rails (~> 6.0)
|
76
246
|
rake (~> 10.0)
|
77
247
|
redis (~> 4.7.0)
|
78
248
|
rspec (~> 3.0)
|
79
|
-
|
80
|
-
|
249
|
+
rspec-rails
|
250
|
+
sidekiq (~> 6.2)
|
81
251
|
|
82
252
|
BUNDLED WITH
|
83
|
-
2.3.
|
253
|
+
2.3.7
|
data/README.md
CHANGED
@@ -1,162 +1,174 @@
|
|
1
1
|
# Communify
|
2
2
|
|
3
|
-
|
3
|
+
Communify is a powerful Ruby gem that enables your backend to seamlessly send SMS through Twilio, push notifications via Firebase Cloud Messaging, and maintain detailed logs of all communications. It also integrates email tracking for messages sent through ActionMailer.
|
4
4
|
|
5
|
-
## Why
|
5
|
+
## Why Choose Communify?
|
6
6
|
|
7
|
-
|
7
|
+
Effective communication is crucial for businesses to engage with their customers about app features, updates, and important information. Communify provides a streamlined solution for integrating SMS, push notifications, and email logging into your Rails application, allowing developers to implement all three communication channels with minimal code.
|
8
8
|
|
9
|
-
|
9
|
+
By simplifying the coding process, Communify enables you to focus on enhancing user experience and fostering strong customer relationships.
|
10
|
+
|
11
|
+
## Features
|
12
|
+
- **SMS Integration**: Easily send SMS messages through Twilio.
|
13
|
+
- **Push Notifications**: Send real-time notifications via Firebase Cloud Messaging.
|
14
|
+
- **Email Logging**: Track all emails sent via ActionMailer.
|
15
|
+
- **Comprehensive Logging**: Maintain logs for all communications, enhancing tracking and auditing capabilities.
|
10
16
|
|
11
17
|
## Installation
|
12
18
|
|
13
|
-
|
19
|
+
To integrate Communify into your Rails application, add the following line to your Gemfile:
|
14
20
|
|
15
21
|
```ruby
|
16
22
|
gem 'communify'
|
17
23
|
```
|
18
24
|
|
19
|
-
|
20
|
-
|
21
|
-
|
25
|
+
Then, run the following command to install:
|
26
|
+
|
27
|
+
bundle install
|
22
28
|
|
23
|
-
|
29
|
+
Alternatively, you can install it directly using:
|
24
30
|
|
25
|
-
|
31
|
+
gem install communify
|
26
32
|
|
27
|
-
|
33
|
+
**Note:** By installing Communify, you automatically include the twilio-ruby gem (version ~> 5.69.0) and the fcmpush gem (version ~> 1.4.4). Communify abstracts the functionality of these gems, streamlining their integration and usage in your application.
|
28
34
|
|
29
35
|
## Requirements
|
30
36
|
|
31
|
-
|
37
|
+
To ensure the successful operation of the Communify gem, please include the following gems in your application's Gemfile:
|
38
|
+
|
39
|
+
gem 'sidekiq'
|
40
|
+
gem 'redis'
|
41
|
+
gem 'dotenv-rails'
|
32
42
|
|
33
|
-
|
43
|
+
Make sure to have Sidekiq running in the background. To start it locally, execute:
|
34
44
|
|
35
|
-
|
45
|
+
bundle exec sidekiq
|
36
46
|
|
37
47
|
## Usage
|
38
48
|
|
39
|
-
|
40
|
-
|
41
|
-
$ rails g communify:install
|
42
|
-
|
43
|
-
This command generates a migration file and a model named CommunifyLog
|
49
|
+
To set up logging for notifications, run the following command in your terminal:
|
44
50
|
|
45
|
-
|
51
|
+
rails g communify:install
|
46
52
|
|
47
|
-
|
53
|
+
This command will generate a migration file and a model named CommunifyLog. Next, execute:
|
48
54
|
|
49
|
-
|
50
|
-
- title -> title of a push notification goes here
|
55
|
+
rails db:migrate
|
51
56
|
|
52
|
-
|
57
|
+
This creates a database table with the following fields:
|
58
|
+
- title: The title of the push notification.
|
53
59
|
|
54
|
-
-
|
60
|
+
- content: The message or notification text to be sent.
|
55
61
|
|
56
|
-
-
|
62
|
+
- recipient: The recipient's mobile number for SMS or the registration ID (generated when the app is installed) for push notifications.
|
57
63
|
|
58
|
-
-
|
64
|
+
- priority: An enum with options:
|
65
|
+
- urgent (0 minutes)
|
66
|
+
- high (5 minutes)
|
67
|
+
- medium (30 minutes)
|
68
|
+
- low (60 minutes)
|
69
|
+
Messages with urgent priority trigger the Sidekiq job immediately, while high priority messages are triggered in 5 minutes, and so on. The default value is urgent.
|
59
70
|
|
60
|
-
-
|
71
|
+
- content_type: Indicates whether the log is for SMS (0) or push notification (1).
|
61
72
|
|
62
|
-
-
|
73
|
+
- status: Stores the status of the message/notification, indicating whether it was successfully sent or failed (including error details).
|
63
74
|
|
64
|
-
-
|
75
|
+
- third_party_id: The ID generated when a message or notification is successfully sent.
|
65
76
|
|
77
|
+
- attempt_count: Automatically generated, indicating the number of attempts made to send the message. Messages are attempted a maximum of three times.
|
66
78
|
|
67
|
-
|
79
|
+
Maintaining logs provides a comprehensive record of all messages and notifications sent, enabling effective tracking and troubleshooting. This aids in identifying delivery issues, enhances user engagement analytics, and ensures compliance with regulatory requirements, ultimately improving communication reliability and efficiency.
|
68
80
|
|
69
|
-
|
81
|
+
### Sending SMS
|
70
82
|
|
71
|
-
|
83
|
+
To configure Twilio keys in your application, run the following command:
|
72
84
|
|
73
|
-
|
74
|
-
|
75
|
-
Uncomment the lines and set the account_sid, auth_token and sender_no with the keys provided in your twilio account.
|
85
|
+
rails g communify:sms
|
76
86
|
|
77
|
-
|
87
|
+
This command creates a communify_sms.rb file in the config/initializers folder. Uncomment the relevant lines and set your account_sid, auth_token, and sender_no with the keys from your Twilio account.
|
78
88
|
|
79
|
-
|
89
|
+
To send an SMS, add the following line in your controller method:
|
80
90
|
|
81
|
-
|
82
|
-
Content -> text to be sent through SMS
|
91
|
+
>Communify::Controllers::Sms.send_message(content, recipient, priority) # Returns the resource_id if successful
|
83
92
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
Priority -> “urgent” / “high” / “medium” / “low”
|
93
|
+
- Content: The text message to be sent.
|
94
|
+
- Recipient: The recipient's number, including the country code (e.g., “+91-1234567890”).
|
95
|
+
- Priority: Choose from “urgent,” “high,” “medium,” or “low.”
|
88
96
|
|
89
97
|
Sample Log:
|
90
98
|
|
91
99
|
<CommunifyLog id: 1, title: "", content: "OTP from abc app: 123456", recipient: "+1-123456789", attempt_count: 1, status: "Message Delivered at 2022-12-12T15:20:45+00:00", third_party_id: "SMaf7c76052f9c5180c03abc5c73d67d9", created_at: "2022-12-12 15:20:45", updated_at: "2022-12-12 15:20:45", priority: "urgent", content_type: "sms">
|
92
100
|
|
93
|
-
###
|
94
|
-
|
95
|
-
To store device information, run the following command in your command line
|
101
|
+
### Sending Push notifications
|
96
102
|
|
97
|
-
|
103
|
+
To configure device information, run the following command:
|
98
104
|
|
99
|
-
|
105
|
+
rails g communify:push_notification
|
100
106
|
|
101
|
-
|
107
|
+
This command generates a migration file, a model and fcmpush.rb in the initializers of your project folder. After that, execute:
|
102
108
|
|
103
|
-
|
109
|
+
rails db:migrate
|
104
110
|
|
105
|
-
This creates a table named Devices with fields
|
111
|
+
This creates a table named Devices with the following fields:
|
106
112
|
|
107
|
-
- device_id
|
113
|
+
- device_id: Registration ID for the device.
|
108
114
|
|
109
|
-
- device_name
|
115
|
+
- device_name: Name of the device (e.g., Android/iOS/Web).
|
110
116
|
|
111
|
-
- person_id, person_type
|
117
|
+
- person_id, person_type: User ID and class name associated with the device
|
112
118
|
|
113
|
-
Get
|
119
|
+
Get the registration ID/device ID (generated by the FCM SDK for each client app instance) from the frontend, link it with a user and store it in the Devices table using:
|
114
120
|
|
115
121
|
>Device.create(device_id: "registration_id goes here", device_name: "Name of the device", person: user)
|
116
122
|
|
117
|
-
|
123
|
+
#### Sending Notifications
|
118
124
|
|
119
|
-
|
125
|
+
1. Generate Service Account Key:
|
126
|
+
- In the Firebase Console, go to Project Settings > Service Accounts
|
127
|
+
- Click on Generate New Private Key and download the JSON file. Store this JSON file securely.
|
128
|
+
- Be sure to add the private key file to your .gitignore.
|
120
129
|
|
121
|
-
|
122
|
-
|
123
|
-
>
|
130
|
+
2. Store FCM Project ID:
|
131
|
+
- In the Firebase Console, navigate to your project.
|
132
|
+
- Go to Project Settings > General to obtain your FCM Project ID.
|
133
|
+
- Store the value in your environment variable with the name FCM_PROJECT_ID to use it with Communify.
|
124
134
|
|
125
|
-
|
135
|
+
3. Configure Initializer:
|
136
|
+
- Add the path to the JSON key file in the initializer generated previously under config.json_key_io.
|
126
137
|
|
127
|
-
|
138
|
+
4. Send Notification:
|
139
|
+
- Add the following line of code in your controller to send a notification:
|
128
140
|
|
129
|
-
|
130
|
-
|
131
|
-
Recipient -> Array of registration ids
|
132
|
-
Example: [“reg_id1”,”reg_id2”]
|
133
|
-
|
134
|
-
Notification Type -> Type of notification i.e keyword that helps Frontend to know where to redirect the user when the notification is clicked
|
135
|
-
|
136
|
-
Other details -> Can be a string or a json converted to a string such that these details are sent to frontend/mobile through the
|
137
|
-
notification but are not visible to the user
|
138
|
-
|
139
|
-
Priority -> “urgent” / “high” / “medium” / “low”
|
141
|
+
>Communify::Controllers::PushNotification.send_push_notification(title, content, recipient, notification_type, other_details, priority)
|
140
142
|
|
141
|
-
-
|
143
|
+
- Title: The title of the notification.
|
144
|
+
- Content: The text of the notification.
|
145
|
+
- Recipient: An array of registration IDs (e.g., ["reg_id1", "reg_id2"]).
|
146
|
+
- Notification Type: A keyword to inform the frontend where to redirect the user when the notification is clicked.
|
147
|
+
- Other Details: Additional information sent to the frontend that is not visible to the user (can be a string or JSON converted to string).
|
148
|
+
- Priority: Choose from "urgent", "high", "medium" or "low".
|
142
149
|
|
143
|
-
|
150
|
+
Note: In this context, registration_id and device_id are used interchangeably.
|
144
151
|
|
145
152
|
Sample log:
|
146
153
|
|
147
154
|
<CommunifyLog id: 1, title: "Notification title", content: "Notification content", recipient: "[\"e2x7BuarRx2tHqv7p80LBJ:APA91bEsh1_ouyuwLvtt06UCX...", attempt_count: 1, status: "Notification Delivered at 2022-11-08T07:17:57+00:0...", third_party_id: "0:1667891877225583%d8a4a6c1d8a4a6c1", created_at: "2022-11-04 14:28:27", updated_at: "2022-11-04 14:28:27", priority: "urgent", content_type: "push_notification">
|
148
155
|
|
149
|
-
###
|
156
|
+
### Maintaining Email logs
|
150
157
|
|
151
|
-
To
|
158
|
+
To enable logging of all emails sent through your application, run the following command:
|
152
159
|
|
153
|
-
|
160
|
+
rails g communify:email
|
154
161
|
|
155
|
-
This
|
162
|
+
This command generates a mail_observer.rb file in the config/initializers directory. Observers provide access to the email message after it has been sent, allowing you to maintain logs in the CommunifyLog table.
|
156
163
|
|
157
|
-
|
164
|
+
The logs will include essential information such as the content, recipient email address, and timestamps of when the emails were sent.
|
158
165
|
|
159
166
|
Sample log:
|
160
167
|
|
161
168
|
<CommunifyLog id: 1, title: "", content: "Subject: Verify your email address, Body: <...", recipient: "ccc@gmail.com", attempt_count: 1, status: "Mail delivered at 2022-12-12T14:47:44+00:00", third_party_id: "63973f107deb7_d32c53f9f6e105da41323d@ip-172-31-10-...", created_at: "2022-12-12 14:47:45", updated_at: "2022-12-12 14:47:45", priority: "urgent", content_type: "email">
|
162
169
|
|
170
|
+
This logging functionality enhances your application's communication audit trail, making it easier to track email interactions with users.
|
171
|
+
|
172
|
+
## Contact & Support
|
173
|
+
If you have any questions, suggestions for enhancements, or encounter any issues while using Communify, please feel free to reach out. We're here to help you maximize your experience with our gem!
|
174
|
+
|
data/communify.gemspec
CHANGED
@@ -9,8 +9,19 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["Kishore RR, Shree Varshini"]
|
10
10
|
spec.email = ["66819332+kishorerr@users.noreply.github.com, rpshreevarshini@gmail.com"]
|
11
11
|
|
12
|
-
spec.summary =
|
13
|
-
|
12
|
+
spec.summary = <<-EOS
|
13
|
+
Gem that simplifies SMS, push notifications, and email logging
|
14
|
+
for Rails applications, enhancing communication with ease.
|
15
|
+
EOS
|
16
|
+
spec.description = <<-EOS
|
17
|
+
Enhance your Rails application’s communication capabilities with Communify,
|
18
|
+
a robust gem designed to seamlessly integrate SMS, push notifications, and email logging.
|
19
|
+
Leveraging the power of Twilio and Firebase Cloud Messaging, Communify enables developers
|
20
|
+
to effortlessly send important alerts and updates while maintaining comprehensive logs of all communications.
|
21
|
+
With its straightforward implementation, Communify simplifies your messaging infrastructure,
|
22
|
+
allowing you to focus on delivering exceptional user experiences. Ideal for developers seeking a
|
23
|
+
unified solution for effective customer engagement.
|
24
|
+
EOS
|
14
25
|
# spec.homepage = "TODO: Put your gem's website or public repo URL here."
|
15
26
|
spec.license = "MIT"
|
16
27
|
spec.required_ruby_version = ">= 2.6.0"
|
@@ -43,5 +54,5 @@ Gem::Specification.new do |spec|
|
|
43
54
|
spec.add_development_dependency "redis", "~>4.7.0"
|
44
55
|
spec.add_development_dependency "sidekiq", "~>6.0.0"
|
45
56
|
spec.add_dependency "twilio-ruby", "~> 5.69.0"
|
46
|
-
spec.add_dependency "
|
57
|
+
spec.add_dependency "fcmpush", "~>1.4.4"
|
47
58
|
end
|
@@ -1,20 +1,21 @@
|
|
1
1
|
require 'communify/workers/push_notification_worker'
|
2
2
|
require 'sidekiq/api'
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
3
|
+
|
4
|
+
class Communify::Controllers::PushNotification
|
5
|
+
def self.send_push_notification(title, content, recipient, notification_type, custom_data, priority = 0)
|
6
|
+
resource = CommunifyLog.new(title: title,
|
7
|
+
content: content,
|
8
|
+
recipient: recipient.to_s,
|
9
|
+
content_type: 1,
|
10
|
+
priority: priority
|
11
|
+
)
|
12
|
+
if resource.save
|
13
|
+
resource.update(status: "Notification Queued at #{DateTime.now}")
|
14
|
+
time = resource.read_attribute_before_type_cast(:priority)
|
15
|
+
result = Communify::Workers::PushNotificationWorker.perform_in(time.minutes.from_now, resource.id, notification_type, custom_data)
|
16
|
+
return resource.id
|
17
|
+
else
|
18
|
+
raise "Error => Resource has not been saved!!"
|
18
19
|
end
|
19
20
|
end
|
20
21
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
class CommunifyLog < ActiveRecord::Base
|
2
|
-
#default values have been set for priority in minutes
|
3
|
-
enum priority
|
4
|
-
enum content_type
|
5
|
-
|
2
|
+
# default values have been set for priority in minutes
|
3
|
+
enum :priority, { urgent: 0, high: 5, medium: 30, low: 60 }
|
4
|
+
enum :content_type, { sms: 0, push_notification: 1, email: 2 }
|
6
5
|
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
Fcmpush.configure do |config|
|
2
|
+
## for message push
|
3
|
+
# firebase web console => project settings => service account => generate new private key
|
4
|
+
|
5
|
+
# pass string of path to credential file to config.json_key_io
|
6
|
+
config.json_key_io = "#{Rails.root}/path/to/service_account_credentials.json"
|
7
|
+
end
|
data/lib/communify/version.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'fcmpush'
|
2
2
|
require 'sidekiq'
|
3
3
|
require 'communify'
|
4
4
|
require 'communify/controllers/push_notification_controller'
|
@@ -8,44 +8,76 @@ module Communify
|
|
8
8
|
include Sidekiq::Worker
|
9
9
|
sidekiq_options dead: false, retry: false
|
10
10
|
|
11
|
-
def perform(resource_id, notification_type,
|
12
|
-
|
13
|
-
|
11
|
+
def perform(resource_id, notification_type, custom_data)
|
12
|
+
service = PushNotificationService.new(resource_id, notification_type, custom_data)
|
13
|
+
service.call
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class PushNotificationService
|
18
|
+
def initialize(resource_id, notification_type, custom_data)
|
19
|
+
@resource = CommunifyLog.find(resource_id)
|
20
|
+
@notification_type = notification_type
|
21
|
+
@custom_data = custom_data
|
22
|
+
@fcm_client = Fcmpush.new(ENV['FCM_PROJECT_ID'])
|
23
|
+
@notification_status = []
|
24
|
+
@response_ids = []
|
25
|
+
end
|
26
|
+
|
27
|
+
def call
|
28
|
+
device_tokens.each do |token|
|
29
|
+
send_notification(token)
|
30
|
+
end
|
31
|
+
update_resource
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def device_tokens
|
37
|
+
JSON.parse(@resource.recipient)
|
38
|
+
end
|
39
|
+
|
40
|
+
def send_notification(token)
|
14
41
|
begin
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
other_details: other_details
|
21
|
-
},
|
22
|
-
notification: {
|
23
|
-
title: @current_resource.title,
|
24
|
-
body: @current_resource.content,
|
25
|
-
sound: 'default'
|
26
|
-
}
|
27
|
-
}
|
28
|
-
response = fcm_client.send(JSON.parse(@current_resource.recipient), options)
|
29
|
-
raise if response[:status_code] != 200 || JSON.parse(response[:body])["success"] == 0
|
30
|
-
rescue
|
31
|
-
@current_resource.update_column(:attempt_count, attempt)
|
32
|
-
attempt = attempt +1
|
33
|
-
if response[:status_code] != 200
|
34
|
-
@current_resource.update_column(:status, "Notification failed at #{DateTime.now} due to error => #{response[:response]}")
|
35
|
-
else
|
36
|
-
@current_resource.update_column(:status, "Notification failed at #{DateTime.now} due to error => #{JSON.parse(response[:body])["results"]}")
|
37
|
-
end
|
38
|
-
if attempt < 4
|
39
|
-
sleep(time.minutes)
|
40
|
-
retry
|
41
|
-
end
|
42
|
+
response = @fcm_client.push(build_payload(token))
|
43
|
+
raise StandardError, "Response code: #{response.code}" if response.code != "200"
|
44
|
+
rescue StandardError => e
|
45
|
+
error = response ? response.inspect : e
|
46
|
+
log_error(token, error)
|
42
47
|
else
|
43
|
-
|
44
|
-
@current_resource.update_column(:third_party_id, message_id.to_s)
|
45
|
-
@current_resource.update_column(:attempt_count, attempt)
|
46
|
-
@current_resource.update_column(:status, "Notification Delivered at #{DateTime.now}")
|
48
|
+
handle_success(token, response)
|
47
49
|
end
|
48
50
|
end
|
51
|
+
|
52
|
+
def build_payload(token)
|
53
|
+
{
|
54
|
+
message: {
|
55
|
+
token: token,
|
56
|
+
notification: {
|
57
|
+
title: @resource.title,
|
58
|
+
body: @resource.content
|
59
|
+
},
|
60
|
+
data: {
|
61
|
+
notification_type: @notification_type,
|
62
|
+
other_details: @custom_data,
|
63
|
+
message: @resource.content
|
64
|
+
}
|
65
|
+
}
|
66
|
+
}
|
67
|
+
end
|
68
|
+
|
69
|
+
def log_error(token, error)
|
70
|
+
@notification_status << "Failed to push notification to token #{token} due to error: #{error}"
|
71
|
+
end
|
72
|
+
|
73
|
+
def handle_success(token, response)
|
74
|
+
@response_ids << response.json[:name]
|
75
|
+
@notification_status << "Push notification delivered to token #{token} at #{DateTime.now} with response: #{response.json}"
|
76
|
+
end
|
77
|
+
|
78
|
+
def update_resource
|
79
|
+
@resource.update(third_party_id: @response_ids.to_s, status: @notification_status.to_s)
|
80
|
+
end
|
49
81
|
end
|
50
82
|
end
|
51
83
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: communify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kishore RR, Shree Varshini
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -95,20 +95,27 @@ dependencies:
|
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: 5.69.0
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: fcmpush
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: 1.
|
103
|
+
version: 1.4.4
|
104
104
|
type: :runtime
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: 1.
|
111
|
-
description:
|
110
|
+
version: 1.4.4
|
111
|
+
description: " Enhance your Rails application’s communication capabilities with
|
112
|
+
Communify, \n a robust gem designed to seamlessly integrate SMS, push notifications,
|
113
|
+
and email logging. \n Leveraging the power of Twilio and Firebase Cloud Messaging,
|
114
|
+
Communify enables developers \n to effortlessly send important alerts and updates
|
115
|
+
while maintaining comprehensive logs of all communications. \n With its straightforward
|
116
|
+
implementation, Communify simplifies your messaging infrastructure, \n allowing
|
117
|
+
you to focus on delivering exceptional user experiences. Ideal for developers seeking
|
118
|
+
a \n unified solution for effective customer engagement.\n"
|
112
119
|
email:
|
113
120
|
- 66819332+kishorerr@users.noreply.github.com, rpshreevarshini@gmail.com
|
114
121
|
executables: []
|
@@ -139,16 +146,17 @@ files:
|
|
139
146
|
- lib/communify/generators/push_notification/push_notification_generator.rb
|
140
147
|
- lib/communify/generators/push_notification/templates/device_migration.erb
|
141
148
|
- lib/communify/generators/push_notification/templates/device_model.erb
|
149
|
+
- lib/communify/generators/push_notification/templates/fcmpush_initializer.erb
|
142
150
|
- lib/communify/generators/sms/sms_generator.rb
|
143
151
|
- lib/communify/generators/sms/templates/communify_sms.erb
|
144
152
|
- lib/communify/version.rb
|
145
153
|
- lib/communify/workers/push_notification_worker.rb
|
146
154
|
- lib/communify/workers/sms_worker.rb
|
147
|
-
homepage:
|
155
|
+
homepage:
|
148
156
|
licenses:
|
149
157
|
- MIT
|
150
158
|
metadata: {}
|
151
|
-
post_install_message:
|
159
|
+
post_install_message:
|
152
160
|
rdoc_options: []
|
153
161
|
require_paths:
|
154
162
|
- lib
|
@@ -163,8 +171,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
163
171
|
- !ruby/object:Gem::Version
|
164
172
|
version: '0'
|
165
173
|
requirements: []
|
166
|
-
rubygems_version: 3.
|
167
|
-
signing_key:
|
174
|
+
rubygems_version: 3.0.9
|
175
|
+
signing_key:
|
168
176
|
specification_version: 4
|
169
|
-
summary:
|
177
|
+
summary: Gem that simplifies SMS, push notifications, and email logging for Rails
|
178
|
+
applications, enhancing communication with ease.
|
170
179
|
test_files: []
|