Class: Mushy::TwilioMessage
- Defined in:
- lib/mushy/fluxs/twilio_message.rb
Instance Attribute Summary
Attributes inherited from Flux
#config, #flow, #id, #masher, #parent_fluxs, #subscribed_to, #type
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from Flux
#convert_this_to_an_array, #convert_to_symbolized_hash, #execute, #execute_single_event, #group_these_results, #guard, #ignore_these_results, inherited, #initialize, #join_these_results, #limit_these_results, #merge_these_results, #model_these_results, #outgoing_split_these_results, #shape_these, #sort_these_results, #standardize_these
Constructor Details
This class inherits a constructor from Mushy::Flux
Class Method Details
.details ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/mushy/fluxs/twilio_message.rb', line 5 def self.details { name: 'TwilioMessage', title: 'Send SMS', fluxGroup: { name: 'Twilio' }, description: 'Send a Twilio Message.', config: { account_sid: { description: 'Your Twilio Account SID.', type: 'text', value: '{{twilio_account_sid}}', }, auth_token: { description: 'Your Twilio Auth Token.', type: 'text', value: '{{twilio_auth_token}}', }, from: { description: 'The phone number from which the message will be sent.', type: 'text', value: '+1{{from}}', }, to: { description: 'The phone number to which the message will be sent.', type: 'text', value: '+1{{to}}', }, body: { description: 'The content of the message.', type: 'text', value: '{{body}}', }, media_url: { description: 'A URL to a file that can be included with the text message, like https://.../your_file.png.', type: 'text', value: '', shrink: true, }, }, examples: { "Basic Example" => { description: "This is what a basic text message.", input: { message: "Hello World!" }, config: { account_sid: 'Your Twilio Account SID', auth_token: 'Your Twilio Auth Token', from: '+15555555555', to: '+14444444444', body: '{{message}}', }, result: { sid: "the sid", date_created: "Sun, 10 Oct 2021 20:16:48 +0000", date_updated: "Sun, 10 Oct 2021 20:16:48 +0000", date_sent: nil, account_sid: "account sid", to: "+15555555555", from: "+14444444444", messaging_service_sid: nil, body: "Hello World!", status: "queued", num_segments: "1", num_media: "0", direction: "outbound-api", api_version: "2010-04-01", price: nil, price_unit: "USD", error_code: nil, error_message: nil, uri: "/2010-04-01/Accounts/ABC/Messages/DEF.json", subresource_uris: { media: "/2010-04-01/Accounts/ABC/Messages/DEF/Media.json" } } }, "A Failed Call" => { description: "This is what a failed call may look like.", result: { code: 20003, detail: "Your AccountSid or AuthToken was incorrect.", message: "Authentication Error - invalid username", more_info: "https://www.twilio.com/docs/errors/20003", status: 401 } }, }, } end |
Instance Method Details
#process(event, config) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/mushy/fluxs/twilio_message.rb', line 94 def process event, config arguments = { from: "From", to: "To", body: "Body", media_url: "MediaUrl", }.select { |x| config[x].to_s != "" } .map { |x| [x[1], config[x[0]].to_s.gsub('"', '\\"')] } .reduce("") { |t, i| "#{t} --data-urlencode \"#{i[0]}=#{i[1]}\"" } config[:command] = "curl -X POST https://api.twilio.com/2010-04-01/Accounts/#{config[:account_sid]}/Messages.json -u #{config[:account_sid]}:#{config[:auth_token]} #{arguments}" result = super event, config JSON.parse result[:text] end |