huginn_elks46_mms_agent 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/huginn_elks46_mms_agent.rb +4 -0
- data/lib/huginn_elks46_mms_agent/elks46_mms_agent.rb +90 -0
- data/spec/elks46_mms_agent_spec.rb +91 -0
- metadata +88 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bacb90895ee3229f7e187be5e92c7af424b581ea68b5f1a3dbbf2cde2c0be8e0
|
4
|
+
data.tar.gz: c93ae24c541d1011822989138dbb8cde6ba38126bdabcea52889bdf619909f08
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: aa9abab11053bcb55b41b8a64dfa414321bc352109acf90eb2c4e066b0c7d54d903777d8799fae58c7368b4636558922537fda68c7b64809d3064aaeacb43f97
|
7
|
+
data.tar.gz: 455471a6adb25022bc7616c46ffe7ba2a7b3d8a350a8d135afd68d4c1e226b2168b2731c20e5e1750dd443a9eaf3645c1f3d3b52ce2aba7e18bace47ec33b83b
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
module Agents
|
4
|
+
class Elks46MmsAgent < Agent
|
5
|
+
no_bulk_receive!
|
6
|
+
cannot_create_events!
|
7
|
+
cannot_be_scheduled!
|
8
|
+
description <<-MD
|
9
|
+
Integration that enables you to **send** MMS 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` - The phone number to send from. Must be an MMS-enabled [Virtual Phone Number](https://46elks.com/products/virtual-numbers) or the text "noreply". We will replace the sender id with a random phone number if "noreply" is used.
|
16
|
+
|
17
|
+
* `to` - The phone number of the recipient in [E.164 format](https://46elks.com/kb/e164).
|
18
|
+
|
19
|
+
* `message` - A message to be sent with the MMS. Either message or image must be present in the API request.
|
20
|
+
|
21
|
+
* `image` - Either a data URL or a publicly accessible URL that points to an image. GIF, PNG and JPEG images are supported. Either image or message must be present in the API request.
|
22
|
+
MD
|
23
|
+
|
24
|
+
def default_options
|
25
|
+
{
|
26
|
+
'api_username' => 'u6xxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
27
|
+
'api_password' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
28
|
+
'from' => 'noreply',
|
29
|
+
'to' => ['+46700000000'],
|
30
|
+
'image' => 'https://46elks.com/press/46elks-blue-png',
|
31
|
+
'message' => 'Hello this is Huginn using 46elks.',
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
def validate_options
|
36
|
+
unless options['api_username'].present?
|
37
|
+
errors.add(:base, '`api_username` is required.')
|
38
|
+
end
|
39
|
+
unless options['api_password'].present?
|
40
|
+
errors.add(:base, '`api_password` is required.')
|
41
|
+
end
|
42
|
+
unless interpolated['from'].present?
|
43
|
+
errors.add(:base, '`from` is required.')
|
44
|
+
end
|
45
|
+
unless interpolated['to'].present?
|
46
|
+
errors.add(:base, '`to` is required.')
|
47
|
+
end
|
48
|
+
unless interpolated['message'].present? || interpolated['image'].present?
|
49
|
+
errors.add(:base, 'At least one of `image` or `message` must be present.')
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def working?
|
54
|
+
!recent_error_logs?
|
55
|
+
end
|
56
|
+
|
57
|
+
def receive(incoming_events)
|
58
|
+
incoming_events.each do |event|
|
59
|
+
interpolate_with event do
|
60
|
+
send_mms(interpolated)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def send_mms(payload)
|
66
|
+
payload['to'].each do |to_recipient|
|
67
|
+
uri = URI('https://api.46elks.com/a1/mms')
|
68
|
+
req = Net::HTTP::Post.new(uri)
|
69
|
+
req.basic_auth options['api_username'], options['api_password']
|
70
|
+
req.set_form_data(
|
71
|
+
:from => payload['from'],
|
72
|
+
:to => to_recipient,
|
73
|
+
:image => payload['image'],
|
74
|
+
:message => payload['message']
|
75
|
+
)
|
76
|
+
|
77
|
+
res = Net::HTTP.start(
|
78
|
+
uri.host,
|
79
|
+
uri.port,
|
80
|
+
:use_ssl => uri.scheme == 'https') do |http|
|
81
|
+
http.request req
|
82
|
+
end
|
83
|
+
|
84
|
+
unless res.is_a?(Net::HTTPSuccess)
|
85
|
+
error("Error: #{res.body}")
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
require 'huginn_agent/spec_helper'
|
3
|
+
|
4
|
+
describe Agents::Elks46MmsAgent do
|
5
|
+
before do
|
6
|
+
default_options = {
|
7
|
+
'api_username' => 'u6xxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
8
|
+
'api_password' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
9
|
+
'from' => 'noreply',
|
10
|
+
'to' => ['+46700000000'],
|
11
|
+
'image' => 'https://46elks.com/press/46elks-blue-png',
|
12
|
+
'message' => 'Hello this is Huginn using 46elks.',
|
13
|
+
}
|
14
|
+
|
15
|
+
@checker = Agents::Elks46MmsAgent.new name: 'elks46 MMS Tester', options: default_options
|
16
|
+
@checker.user = users(:bob)
|
17
|
+
@checker.save!
|
18
|
+
end
|
19
|
+
|
20
|
+
def event_with_payload(payload)
|
21
|
+
event = Event.new
|
22
|
+
event.agent = agents(:bob_manual_event_agent)
|
23
|
+
event.payload = payload
|
24
|
+
event.save!
|
25
|
+
event
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
def stub_methods
|
30
|
+
stub.any_instance_of(Agents::Elks46MmsAgent).send_mms do |params|
|
31
|
+
@sent_messages << params
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe 'validation' do
|
36
|
+
before do
|
37
|
+
expect(@checker).to be_valid
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should validate the presence of api_username" do
|
41
|
+
@checker.options[:api_username] = ''
|
42
|
+
expect(@checker).not_to be_valid
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should validate the presence of api_password" do
|
46
|
+
@checker.options[:api_password] = ''
|
47
|
+
expect(@checker).not_to be_valid
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should validate the presence of from" do
|
51
|
+
@checker.options[:from] = ''
|
52
|
+
expect(@checker).not_to be_valid
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should validate the presence of to" do
|
56
|
+
@checker.options[:to] = ''
|
57
|
+
expect(@checker).not_to be_valid
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should validate the presence of message or image" do
|
61
|
+
@checker.options[:message] = ''
|
62
|
+
@checker.options[:image] = ''
|
63
|
+
expect(@checker).not_to be_valid
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe '#receive' do
|
68
|
+
before do
|
69
|
+
stub_methods
|
70
|
+
@sent_messages = []
|
71
|
+
|
72
|
+
expect(@checker).to be_valid
|
73
|
+
end
|
74
|
+
it "should receive event" do
|
75
|
+
event = event_with_payload from: "noreply", to: ["+46700000000"], image: "https://46elks.com/press/46elks-blue-png", message: "Hello this is Huginn using 46elks."
|
76
|
+
@checker.receive [event]
|
77
|
+
|
78
|
+
expect(@sent_messages).to eq([
|
79
|
+
{
|
80
|
+
"api_username": 'u6xxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
81
|
+
"api_password": 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
82
|
+
"from": 'noreply',
|
83
|
+
"to": ["+46700000000"],
|
84
|
+
"image": 'https://46elks.com/press/46elks-blue-png',
|
85
|
+
"message": 'Hello this is Huginn using 46elks.',
|
86
|
+
}.stringify_keys
|
87
|
+
])
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
end
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: huginn_elks46_mms_agent
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.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
|
+
email:
|
57
|
+
- anton@46elks.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- lib/huginn_elks46_mms_agent.rb
|
63
|
+
- lib/huginn_elks46_mms_agent/elks46_mms_agent.rb
|
64
|
+
- spec/elks46_mms_agent_spec.rb
|
65
|
+
homepage: https://github.com/antonmyr/huginn_elks46_mms_agent
|
66
|
+
licenses: []
|
67
|
+
metadata: {}
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubygems_version: 3.0.3
|
84
|
+
signing_key:
|
85
|
+
specification_version: 4
|
86
|
+
summary: Send MMS from Huginn using 46elks.
|
87
|
+
test_files:
|
88
|
+
- spec/elks46_mms_agent_spec.rb
|