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?
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;
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.
See Publish(PublishRequest).
Amazon.SimpleNotificationService.Model.PublishRequest has a PhoneNumber property, used for setting the number when sending a direct SMS message.
Related
Attempting this on .NET Core 3.1
After several hours of trying to publish a photo to my public facebook page (as in business page) of which I am the admin and have a long-term token for...
I keep getting the following response to my request using the official Facebook SDK for .NET. However, the image itself is never loaded.
{{"id":"786692942226147","post_id":"113260773923227_786692942226147"}}
The request looks like
var imageMedia = new FacebookMediaObject { FileName = file.FileName, ContentType = file.ContentType };
var stream = file.OpenReadStream();
var bytes = await stream.ReadAsByteArrayAsync();
imageMedia.SetValue(bytes);
var fbClient = new FacebookClient(credential.Token)
{
AppId = _config.GetValue<string>("FacebookClientId"),
AppSecret = _config.GetValue<string>("FacebookSecret")
};
dynamic parameters = new ExpandoObject();
parameters.message = request.Message;
parameters.file = imageMedia;
var result = await fbClient.PostTaskAsync($"{credential.PageId}/photos", parameters, token);
I'm sure it has something to do with the parameters I'm passing in, like parameters.file... but the docs for this thing are VERY unclear... as in "literally does not exist"
Anyone with experience getting this working, please point me in the right direction?
The solution is to change parameters.file to parameters.image...
I am trying to use the Direct Line v3.0 NuGet package to send a message to my bot. I am following the sample on Github, but I'm not getting the behavior I expect.
Here is the sample code:
DirectLineClient client = new DirectLineClient(directLineSecret);
var conversation = await client.Conversations.StartConversationAsync();
while (true)
{
string input = Console.ReadLine().Trim();
if (input.ToLower() == "exit")
{
break;
}
else
{
if (input.Length > 0)
{
Activity userMessage = new Activity
{
From = new ChannelAccount(fromUser),
Text = input,
Type = ActivityTypes.Message
};
await client.Conversations.PostActivityAsync(conversation.ConversationId, userMessage);
}
}
}
And here is my code:
var directLineSecret = "MY_SECRET";
var client = new DirectLineClient(directLineSecret);
var conversation = await client.Conversations.StartConversationAsync();
var testActivity = new Activity
{
From = new ChannelAccount(name: "Proactive-Engine"),
Type = ActivityTypes.Message,
Text = "Hello from the PCE!"
};
var response = await client.Conversations.PostActivityAsync(conversation.ConversationId, testActivity);
I'm logging all the messages my bot receives. I can talk to the bot at its endpoint on Azure using the Bot Emulator, so I have confidence that it's working through the web chat API. However when I run the code above, the bot logs only a conversationUpdate message. The message I send does not get logged, and the value of response is null.
I'm hoping someone can help me find out where I'm going wrong here. Thanks!
Look at how the demo instantiates ChannelAccount:
new ChannelAccount(fromUser)
Then look at the ChannelAccount constructor signature:
public ChannelAccount(string id = null, string name = null)
This means that fromUser is passed as id. But look at how you instantiated ChannelAccount:
new ChannelAccount(name: "Proactive-Engine")
That code doesn't pass an id, it passes a name. So, you can change it like this:
new ChannelAccount("Proactive-Engine")
If your chatbot needs the name, then instantiate like this:
new ChannelAccount("MyChatbotID", "MyChatbotName")
I've been going thumbing through the documentation and searching the internet to find documenation on how to add attachments to created templates. I'm using darrencauthon's CSharp-Sparkpost to handle the API calls. So far what I have is not working. Does anyone have a working solution (possible?) or a better solution for C#? I'm not opposed to using a different library. This is the link to CSharp-Sparkpost
Here's what I've got so far:
var t = new Transmission();
t.Content.From.Email = "from#thisperson.com";
t.Content.TemplateId = "my-template-email";
new Recipient
{
Address = new Address { Email = recipient }
}
.Apply(t.Recipients.Add);
new Attachment
{
Data = //CSVDATA,
Name = "Table.csv",
Type = "text/csv"
}.Apply(t.Content.Attachments.Add);
var client = new SparkPost.Client(Util.GetPassword("sparkpostapikey"));
client.Transmissions.Send(t).Wait();
I've verified that I can send this attachment without a template and also verified that I can send this template without the attachment. So... the Email is getting sent; however, the content received is only the template and substitution data. No attachment with the template email.
Using Darren's library, and combining the requirements for my project, this is the solution I've come up with. I'm just making an additional API call to grab the template Html so I can build the transmission without having to send the template_id. Still using the CSharp-Sparkpost library to make all of the calls. I modified Darren's example SendInline program as such:
static async Task ExecuteEmailer()
{
var settings = ConfigurationManager.AppSettings;
var fromAddr = settings["fromaddr"];
var toAddr = settings["toaddr"];
var trans = new Transmission();
var to = new Recipient
{
Address = new Address
{
Email = toAddr
},
SubstitutionData = new Dictionary<string, object>
{
{"firstName", "Stranger"}
}
};
trans.Recipients.Add(to);
trans.SubstitutionData["firstName"] = "Sir or Madam";
trans.Content.From.Email = fromAddr;
trans.Content.Subject = "SparkPost sending attachment using template";
trans.Content.Text = "Greetings {{firstName or 'recipient'}}\nHello from C# land.";
//Add attachments to transmission object
trans.Content.Attachments.Add(new Attachment()
{
Data = Convert.ToBase64String(System.IO.File.ReadAllBytes(#"C:\PathToFile\ExcelFile.xlsx")),
Name = "ExcelFile.xlsx",
Type = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
});
Console.Write("Sending mail...");
var client = new Client(settings["apikey"]);
client.CustomSettings.SendingMode = SendingModes.Sync;
//retrieve template html and set Content.Html
var templateResponse = await client.Templates.Retrieve("template-email-test");
trans.Content.Html = templateResponse.TemplateContent.Html;
//Send transmission
var response = client.Transmissions.Send(trans);
Console.WriteLine("done");
}
Oh actually, I see now -- you are talking about adding attachments to templates, not attachments.
My answer to that is that back when I developed this library, attachment on templates was not supported by SparkPost itself.
My library allows you to try it, but that's because every template and non-template emails are considered "transmissions." So if you create a transmission, it has the option of adding attachments... but if you send the transmission with a template id, the attachment is ignored.
I could throw an error, or somehow design the API around this limitation, but what if they stopped ignoring the attachment but my library threw an error? I designed the library for flexibility as the SparkPost web API grew, and I didn't want my library to get in the way.
If you want to test if you're sending the attachment right, send your transmission without a transmission id, and instead with a subject and email body. If the email goes through and you get an attachment, then you know it's because of this template/attachment restriction from SparkPost.
NOTE: I'm putting this answer on Stack Overflow, and it's possible that this dated message will no longer be valid in the future.
I'm Darren Cauthon, the primary author of this library.
I have attachment support in my acceptance tests, which are run before each release. The link is below, but the code should be as simple as:
// C#
var attachment = File.Create<Attachment>("testtextfile.txt");
transmission.Content.Attachments.Add(attachment);
https://github.com/darrencauthon/csharp-sparkpost/blob/3a8cb1efbb8c9a0448c71c126ce7f88759867fb0/src/SparkPost.Acceptance/TransmissionSteps.cs#L56
I created a windows form app and have been looking for a way to pass authentication to connect to the server and retrieve product information.
Couldn't find any examples anywhere. Can someone help me?
Here is the api link.
If you check out this link you might get everything you need:
https://github.com/nickvane/Magento-RestApi/wiki/Authentication-steps
Usage of the library can be found here:
https://github.com/nickvane/Magento-RestApi
(just scroll down a bit)
So in order to authenticate your code, you can use:
var client = new MagentoApi()
.Initialize("http://www.yourmagentourl.com", "ConsumerKey", "ConsumerSecret")
.AuthenticateAdmin("UserName", "Password");
or the other variants that exist in the last above link.
Please use the code below. I think it will help you
var client = new MagentoApi()
.SetCustomAdminUrlPart(AdminUrlPart)
.Initialize(StoreUrl, ConsumerKey, ConsumerSerect)
.AuthenticateAdmin(AdminUserName, AdminPassword);
var filter = new Magento.RestApi.Models.Filter();
//filter.FilterExpressions.Add(new FilterExpression("name", ExpressionOperator.like, "L%"));
filter.PageSize = 100;
filter.Page = 0;
// var response = await client.GetProducts(filter);
var sCode = Task.Run(async () => await client.GetProducts(filter));
MagentoApiResponse<IList<Magento.RestApi.Models.Product>> product = sCode.Result;
I am trying to send a notification (not app requests) to registered users, server-side using the C# Facebook SDK. I actually get a success message, but no notification is sent. Our app is not in sandbox and has canvas enabled. The code below show attempts to send both notifications and app requests--the notifications do nothing, but the app request works:
var fb = new FacebookClient();
dynamic result = fb.Get("oauth/access_token", new
{
client_id = "MY_APP_KEY",
client_secret = "MY_SECRET",
grant_type = "client_credentials"
});
fb.AccessToken = result.access_token;
dynamic nparams = new ExpandoObject();
nparams.template = "Hello from my app!";
nparams.href = "Home";
dynamic requestParams = new ExpandoObject();
requestParams.message = "Hi there";
requestParams.title = "Please use this awesome app";
foreach (string facebookID in facebookIDs)
{
// This returns success:true, but doesn't actually do anything
var postResult = fb.Post(facebookID + "/notifications", nparams);
// This works and shows a request in the app center
var postResult2 = fb.Post(facebookID + "/apprequests", requestParams);
}
The fact that apprequests send here tells me the access token is ok, so why don't notifications work? We really need to do this server-side--has anyone been able to do that?
Got a response from facebook on this . . . basically, that this feature is in beta and it may just not work, despite giving Success responses
Good snippet Anthony. Appears to be working consistently now. +1 for your attempt.
PS: In case anyone stumbles upon this code, "facebookID" is a numeric Id and can be derived using the following link http://findmyfacebookid.com/