huginn_elks46_sms_agent 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +7 -0
- data/lib/huginn_elks46_sms_agent.rb +4 -0
- data/lib/huginn_elks46_sms_agent/elks46_sms_agent.rb +89 -0
- data/spec/elks46_sms_agent_spec.rb +88 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 42c24bf6d807ef54c659e02cc43ebe4eece472610185f584601b7c175de320b6
|
4
|
+
data.tar.gz: c74dd69fd88a8c795145c6e21cec9da22b39fd112bd443e041ef139953f62e54
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 36ea26a678411140fc56600f25dc0e9643b1b56148c9ed209a654537786c80ce56764454d6967e6f5843d100a4c4009aec4bd7eca8c692d04ed54a992833dbfd
|
7
|
+
data.tar.gz: ce97df389032cde21a1406d6092ca40b7dd87b964299df42048904a7c191a741f96f47b1c5ac18a93b22a4316f900285769c3c7617640c2705e482102a45958e
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (c) 2020 antonmyr
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
module Agents
|
4
|
+
class Elks46SmsAgent < Agent
|
5
|
+
no_bulk_receive!
|
6
|
+
cannot_create_events!
|
7
|
+
cannot_be_scheduled!
|
8
|
+
description <<-MD
|
9
|
+
Integration that enables you to **send** SMS from Huginn.
|
10
|
+
|
11
|
+
Define your API credentials (`api_username` and `api_password`) which you can find at your [46elks account](https://46elks.com).
|
12
|
+
|
13
|
+
Options:
|
14
|
+
|
15
|
+
* `from` - Either a [text sender ID](https://46elks.com/kb/text-sender-id) or a [virtual phone number](https://46elks.com/products/virtual-numbers) in [E.164 format](https://46elks.com/kb/e164) if you want to be able to receive replies.
|
16
|
+
|
17
|
+
* `to` - The phone number of the recipient in [E.164 format](https://46elks.com/kb/e164).
|
18
|
+
|
19
|
+
* `message` - The message you want to send.
|
20
|
+
MD
|
21
|
+
|
22
|
+
# There is a form_configurable for extra options, this can be used instead of the default options.
|
23
|
+
# It's located in app/concerns/form_configurable.rb
|
24
|
+
def default_options
|
25
|
+
{
|
26
|
+
'api_username' => 'u6xxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
27
|
+
'api_password' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
28
|
+
'from' => 'Huginn',
|
29
|
+
'to' => ['+46700000000'],
|
30
|
+
'message' => 'Hello this message from your friend Huginn.',
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
def validate_options
|
35
|
+
unless options['api_username'].present?
|
36
|
+
errors.add(:base, '`api_username` is required.')
|
37
|
+
end
|
38
|
+
unless options['api_password'].present?
|
39
|
+
errors.add(:base, '`api_password` is required.')
|
40
|
+
end
|
41
|
+
unless interpolated['from'].present?
|
42
|
+
errors.add(:base, '`from` is required.')
|
43
|
+
end
|
44
|
+
unless interpolated['to'].present?
|
45
|
+
errors.add(:base, '`to` is required.')
|
46
|
+
end
|
47
|
+
unless interpolated['message'].present?
|
48
|
+
errors.add(:base, '`message` is required.')
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def working?
|
53
|
+
!recent_error_logs?
|
54
|
+
end
|
55
|
+
|
56
|
+
def receive(incoming_events)
|
57
|
+
incoming_events.each do |event|
|
58
|
+
interpolate_with event do
|
59
|
+
send_sms(interpolated)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def send_sms(payload)
|
65
|
+
payload['to'].each do |to_recipient|
|
66
|
+
uri = URI('https://api.46elks.com/a1/sms')
|
67
|
+
req = Net::HTTP::Post.new(uri)
|
68
|
+
req.basic_auth payload['api_username'], payload['api_password']
|
69
|
+
req.set_form_data(
|
70
|
+
:from => payload['from'],
|
71
|
+
:to => to_recipient,
|
72
|
+
:message => payload['message']
|
73
|
+
)
|
74
|
+
|
75
|
+
res = Net::HTTP.start(
|
76
|
+
uri.host,
|
77
|
+
uri.port,
|
78
|
+
:use_ssl => uri.scheme == 'https') do |http|
|
79
|
+
http.request req
|
80
|
+
end
|
81
|
+
|
82
|
+
unless res.is_a?(Net::HTTPSuccess)
|
83
|
+
error("Error: #{res.body}")
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
require 'huginn_agent/spec_helper'
|
3
|
+
|
4
|
+
describe Agents::Elks46SmsAgent do
|
5
|
+
before do
|
6
|
+
default_options = {
|
7
|
+
api_username: 'u6xxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
8
|
+
api_password: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
9
|
+
from: 'Huginn',
|
10
|
+
to: ['+46700000000'],
|
11
|
+
message: 'This is a message from your friend Huginn.',
|
12
|
+
}
|
13
|
+
|
14
|
+
@checker = Agents::Elks46SmsAgent.new name: 'elks46 SMS Tester', options: default_options
|
15
|
+
@checker.user = users(:bob)
|
16
|
+
@checker.save!
|
17
|
+
end
|
18
|
+
|
19
|
+
def event_with_payload(payload)
|
20
|
+
event = Event.new
|
21
|
+
event.agent = agents(:bob_manual_event_agent)
|
22
|
+
event.payload = payload
|
23
|
+
event.save!
|
24
|
+
event
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
def stub_methods
|
29
|
+
stub.any_instance_of(Agents::Elks46SmsAgent).send_sms do |params|
|
30
|
+
@sent_messages << params
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe 'validation' do
|
35
|
+
before do
|
36
|
+
expect(@checker).to be_valid
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should validate the presence of api_username" do
|
40
|
+
@checker.options[:api_username] = ''
|
41
|
+
expect(@checker).not_to be_valid
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should validate the presence of api_password" do
|
45
|
+
@checker.options[:api_password] = ''
|
46
|
+
expect(@checker).not_to be_valid
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should validate the presence of from" do
|
50
|
+
@checker.options[:from] = ''
|
51
|
+
expect(@checker).not_to be_valid
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should validate the presence of to" do
|
55
|
+
@checker.options[:to] = ''
|
56
|
+
expect(@checker).not_to be_valid
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should validate the presence of message" do
|
60
|
+
@checker.options[:message] = ''
|
61
|
+
expect(@checker).not_to be_valid
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe '#receive' do
|
66
|
+
before do
|
67
|
+
stub_methods
|
68
|
+
@sent_messages = []
|
69
|
+
|
70
|
+
expect(@checker).to be_valid
|
71
|
+
end
|
72
|
+
it "should receive event" do
|
73
|
+
event = event_with_payload from: "Huginn", to: ["+46700000000"],message: "This is a message from your friend Huginn."
|
74
|
+
@checker.receive [event]
|
75
|
+
|
76
|
+
expect(@sent_messages).to eq([
|
77
|
+
{
|
78
|
+
"api_username": 'u6xxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
79
|
+
"api_password": 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
80
|
+
"from": 'Huginn',
|
81
|
+
"to": ["+46700000000"],
|
82
|
+
"message": 'This is a message from your friend Huginn.',
|
83
|
+
}.stringify_keys
|
84
|
+
])
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: huginn_elks46_sms_agent
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- antonmyr
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-07-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: huginn_agent
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: |
|
56
|
+
## What is this?
|
57
|
+
|
58
|
+
This is an agent that allows you to send SMS with the help of https://46elks.com.
|
59
|
+
|
60
|
+
## Want more?
|
61
|
+
|
62
|
+
Check out these agents as well:
|
63
|
+
|
64
|
+
- [Sending MMS from Huginn]()
|
65
|
+
- [Making Phone calls from Huginn]()
|
66
|
+
email:
|
67
|
+
- anton@46elks.com
|
68
|
+
executables: []
|
69
|
+
extensions: []
|
70
|
+
extra_rdoc_files: []
|
71
|
+
files:
|
72
|
+
- LICENSE.txt
|
73
|
+
- lib/huginn_elks46_sms_agent.rb
|
74
|
+
- lib/huginn_elks46_sms_agent/elks46_sms_agent.rb
|
75
|
+
- spec/elks46_sms_agent_spec.rb
|
76
|
+
homepage: https://github.com/antonmyr/huginn_elks46_sms_agent
|
77
|
+
licenses:
|
78
|
+
- MIT
|
79
|
+
metadata: {}
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubygems_version: 3.0.3
|
96
|
+
signing_key:
|
97
|
+
specification_version: 4
|
98
|
+
summary: Send SMS from Huginn using https://46elks.com.
|
99
|
+
test_files:
|
100
|
+
- spec/elks46_sms_agent_spec.rb
|