1

As per the docs, to send an SMS for single number, we need not create SNS topic. Clearly, they have given a sample code which shows we can set phone number for publish request method

http://docs.aws.amazon.com/sns/latest/dg/sms_publish-to-phone.html

As per the java docs, I can clearly see that method.

http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/sns/model/PublishRequest.html#setPhoneNumber-java.lang.String-

But, how do we implement same in c#? I couldn't find any method to send an sms without creating an SNS topic.

Can someone guide me how do I send an SMS without creating an SNS topic from C# SDK?

RecklessSergio
  • 806
  • 3
  • 10
  • 34

3 Answers3

2

I hope this helps:

var smsAttributes = new Dictionary<string, MessageAttributeValue>();
MessageAttributeValue senderID = new MessageAttributeValue();
senderID.DataType = "String";
senderID.StringValue = "mySenderId";

MessageAttributeValue sMSType = new MessageAttributeValue();
sMSType.DataType = "String";
sMSType.StringValue = "Promotional";

////MessageAttributeValue maxPrice = new MessageAttributeValue();
////maxPrice.DataType = "Number";
////maxPrice.StringValue = "0.1";

CancellationTokenSource source = new CancellationTokenSource();
CancellationToken token = source.Token;

smsAttributes.Add("AWS.SNS.SMS.SenderID", senderID);
smsAttributes.Add("AWS.SNS.SMS.SMSType", sMSType);
////smsAttributes.Add("AWS.SNS.SMS.MaxPrice", maxPrice);

PublishRequest publishRequest = new PublishRequest();
publishRequest.Message = vm.Message;
publishRequest.MessageAttributes = smsAttributes;
publishRequest.PhoneNumber = vm.PhoneNumber;
AmazonSimpleNotificationServiceClient client = new AmazonSimpleNotificationServiceClient(vm.AccessKey, vm.SecretKey, config);
AmazonSNSResponse resp = new AmazonSNSResponse();
await client.PublishAsync(publishRequest);

AmazonSNSResponse response = new AmazonSNSResponse();
response.Status = HttpStatusCode.OK.ToString();
response.Message = "Success";
return response;    
SHR
  • 7,940
  • 9
  • 38
  • 57
0

I believe you'll find the answer here: https://forums.aws.amazon.com/thread.jspa?threadID=250183&tstart=0

Basically what is saying and quote: "...PhoneNumber property was added in version 3.1.1.0 of AWSSDK.SimpleNotificationService..."

I haven't put example code since the PhoneNumber property is what is missing in the request, the rest should work as similar to Java Example :D.

Enrique Ramos
  • 36
  • 1
  • 5
  • Link is not working. It is saying The specified thread [0] was not found. – RecklessSergio Jul 11 '18 at 01:07
  • 1
    I tested the link myself again and is working is probably no available for your location, I updated the answer with the comment they put inside the forum. I was in the same situation and after upgrade the package version I was able to see the property. – Enrique Ramos Jul 12 '18 at 02:25
-1

See Publish(PublishRequest).

Amazon.SimpleNotificationService.Model.PublishRequest has a PhoneNumber property, used for setting the number when sending a direct SMS message.

Michael - sqlbot
  • 169,571
  • 25
  • 353
  • 427