Unclear Documentation
christopheragnus opened this issue · comments
Hi there,
I have gotten the authentication tokens working and have created a number using the provision method. How do I actually send a SMS message? I get a 400 error / bad request error.
Your documentation is very unclear on how to add a JSON payload. Anyone able to get this working that could guide me?
Cheers,
Chris
When you say isnt very clear did you check the payload doc?
Heres a sample script if it helps, make sure you've done a provisioning call first to get a mobile number associated with the API keys (included below)
require 'Telstra_Messaging'
api_instance = Telstra_Messaging::AuthenticationApi.new
client_id = "clientid" # String |
client_secret = "clientsecret" # String |
grant_type = "client_credentials" # String |
result = api_instance.auth_token(client_id, client_secret, grant_type)
Telstra_Messaging.configure do |config|
# Configure OAuth2 access token for authorization: auth
config.access_token = result.access_token
end
api_instance = Telstra_Messaging::ProvisioningApi.new
#activate number
arr = {'activeDays' => 30}
body = Telstra_Messaging::ProvisionNumberRequest.new(arr)
result = api_instance.create_subscription(body)
p result
api_instance = Telstra_Messaging::MessagingApi.new
arr = {'to': '0400000000', 'body' => 'hello world'};
payload = Telstra_Messaging::SendSMSRequest.new(arr)
result = api_instance.send_sms(payload)
p result
Hi @developersteve,
Thanks for sending that! I was confused on how to send the acutal payload (I got the provision part working). I will give it a test and report back.
This bit wasn't in the docs:
api_instance = Telstra_Messaging::MessagingApi.new
arr = {'to': '0400000000', 'body' => 'hello world'};
payload = Telstra_Messaging::SendSMSRequest.new(arr)
result = api_instance.send_sms(payload)
p result
EDIT: SMS works!
Do you have any code snippets/example to test out MMS?
Where do I find the payload doc?
Cheers,
Chris
Yup see if this works, just place after the auth call.
Note: img = 'base64' - without the base64 and file type start. You can also send multiple images by including them in the mms_content array in the same format as the mms var below
mms = {'type': 'image/png', 'filename': 'test.png', 'payload': img }
api_instance = Telstra_Messaging::MessagingApi.new
send_mms_request = Telstra_Messaging::SendMmsRequest.new
send_mms_request.to = '0400000000'
send_mms_request.mms_content = [mms]
result = api_instance.send_mms(send_mms_request)
p result
For more info check out https://github.com/telstra/MessagingAPI-SDK-ruby/blob/master/docs/SendMmsRequest.md which also links to the mms array payload doc
Hmm, I'm can receive the MMS but I am not receiving image itself.
My console output shows the HTTP status code was 201.
ETHON: performed EASY effective_url=https://tapi.telstra.com/v2/messages/mms response_code=201 return_code=ok total_time=1.38437
=> #<Telstra_Messaging::MessageSentResponse:0x007fec825e95e0 @messages=[#<Telstra_Messaging::Message:0x007fec825e9338 @to="+61466979228", @delivery_status="MessageWaiting", @message_id="jkcols1mmjn478_M.kmmf.mmsc.telstra.com", @message_status_url="https://tapi.telstra.com/v2/messages/mms/jkcols1mmjn478_M.kmmf.mmsc.telstra.com/status">], @message_type="MMS", @number_segments=1, @country="[{:AUS=>1}]">
I am sending this into IRB.
api_instance = Telstra_Messaging::MessagingApi.new
send_mms_request = Telstra_Messaging::SendMmsRequest.new
mms = {'type': 'image/png', 'filename': image, 'payload': 'base64' }
send_mms_request.to = '+my number here'
send_mms_request.mms_content = [mms]
result = api_instance.send_mms(send_mms_request)
p result
EDIT: I think its something to do with image
.
image = require './test.png'
where test.png is a image file in the same directory. This doesn't load the image though and it doesn't work.
What does payload do?
Any ideas?
The payload is the image in base64, you cant send 'base64' as a string.
If you want to load an image and convert to base64 for sending you need to do something like this ...
require 'base64'
Base64.encode64(File.open("file_path", "rb").read)
@developersteve Hey thanks for that!
This works for me now and I'm now properly receiving images!
require 'base64'
encoding = Base64.strict_encode64(File.open("./test.png", "rb").read)
Another question, when retrieving images from MMS/SMS, how long are they stored for?
Does it retrieve the images if they are in array in Base64 format as well?
Are there size restrictions for the images?
Woot, good to hear 👍
They arent stored just sent to the nominated number, also its important to note that currently the limitation on image size is 2 meg. You are actually able to receive them back to the number via the notifyURL as long as the images are no bigger than 2meg as well.