I am using PushSharp library to send push notification from my application.
PushService push = new PushService();
var reg_id_d = "APA91bETd-LsqnZjA-HKrnBOY3FbEhmWchpiwuhRkiv4gUdGDuvwDRB7YURICZ131XppDAUNUBLGe_vEPkQ-JR8UaVX7Y-NCkEfastCBLIYcUoFtt5cPafeKXHywi0WGDYW33ZQqr3oy";
var project_id_d = "482885626272";
var api_key_d = "AIzaSyAbh7R5KQR3KM7W_y-yS-Ao-JNiihNz7tE"; // "AIzaSyDcKfuW77GTwA46L6sqD41YhGf2j5S8o2w";
var package_name_d = "com.get.deviceid";
push.StartGoogleCloudMessagingPushService(new GcmPushChannelSettings(project_id_d, api_key_d, package_name_d));
push.QueueNotification(NotificationFactory.AndroidGcm()
.ForDeviceRegistrationId(reg_id_d)
.WithCollapseKey("NONE")
.WithJson("{\"alert\":\"Alert Text!\",\"badge\":\"1\"}"));
I am getting notification on my device but with blank message..
I have tried with sever code available in C# to send GCM push notification, but getting same problem of having blank message.
I tried using PHP to send notification. and it is working as expected. so, I am not sure what is wrong in my above code. Can anyone please help me on this?
I tried using different code available around.. but none of those were working..
finally I tried https://stackoverflow.com/a/11651066/1005741 and it works like a charm!
I encountered the same issue, where I received an empty message. My code was a bit different and i was using different libraries: the client was wrapped with phonegap pushPlugin ,and the server code is as follows :
...
// com.google.android.gcm.server.Sender.Sender(String key)
gcmSender = new Sender(androidAPIkey);
// com.google.android.gcm.server.Message
Message message = new Message.Builder().addData("alert", "test message" /*notif.getAlert()*/).build();
Result result = gcmSender.sendNoRetry(message, /* device token */ notif.getToken());
nr.add(result, notif.getToken());
...
The reason why my messages where empty is due to the fact that phonegap looks for "message" , "msgcnt" or "soundname" while parsing the extras from the intent. So, this was the solution in my case :
Message message = new Message.Builder().addData("message", notif.getAlert()).build();
Hope this will help someone
Change alert to message, Please see code below for your reference:
////---------------------------
//// ANDROID GCM NOTIFICATIONS
////---------------------------
////Configure and start Android GCM
////IMPORTANT: The API KEY comes from your Google APIs Console App, under the API Access section,
//// by choosing 'Create new Server key...'
//// You must ensure the 'Google Cloud Messaging for Android' service is enabled in your APIs Console
push.RegisterGcmService(new GcmPushChannelSettings("senderid", "apikey", "com.xx.m"));
//Fluent construction of an Android GCM Notification
//IMPORTANT: For Android you MUST use your own RegistrationId here that gets generated within your Android app itself!
push.QueueNotification(new GcmNotification().ForDeviceRegistrationId("regid")
.WithCollapseKey("score_update")
.WithJson("{\"message\":\"syy!\",\"badge\":7,\"sound\":\"sound.caf\"}")
.WithTimeToLive(108)
);
Related
I am currently working on automatic updates for Passbook (wallet) tickets and am experiencing some trouble using the Pushsharp library by Redth.
I am using a Push notification certificate from the apple developer portal.
I have tried to export my certificate as .p12, .pem and tried to use only the private key as .12 or .pem but nothing works. This is my full certificate (information is blanked out for security reasons):
https://cdn.pbrd.co/images/HUJtb7b.png
I dont have enough reputation to post images so a link is all i can provide.
var succeeded = 0;
var failed = 0;
var attempted = 0;
var config = new ApnsConfiguration(ApnsConfiguration.ApnsServerEnvironment.Sandbox, ConfigManager.CertPath + "PushCertificateV2.p12", ConfigManager.lvppass, false);
var broker = new ApnsServiceBroker(config);
broker.OnNotificationFailed += (notification, exception) =>
{
failed++;
};
broker.OnNotificationSucceeded += (notification) =>
{
succeeded++;
};
broker.Start();
attempted++;
broker.QueueNotification(new ApnsNotification
{
DeviceToken = pushtoken,
Payload = JObject.Parse("{ \"aps\" : { \"alert\" : \"Test notification\" } }")
});
broker.Stop();
The purpose is to send a push notification to the APNS and receive an answer, sadly i am only receiving the error: Apns notification error: 'InvalidToken'.
If it means my Pushtoken from the device is incorrect it would be weird because i am using the pushtoken i recieved from the iPhone and checked it multiple times to be sure.
I have tried searching for solutions on the web but have not found a working one so far, so any help would be greatly appreciated.
Thank you in advance.
Okay, for anyone having the same issues in the future, it turned out i needed to use the same certificate i use for signing the passes and updating them. And that you cannot use the sandbox APNS because all passbook tokens are production tokens.
You really need to be able to send raw json at facebook to take advantage of all of the facebook messenger features but I see no way to do that in the MS bot SDK. (version 4). Here is what I think should work, but no luck. If I set the Text property of a reply activity it just shows up as text on messenger (as expected). If I set the ChannelData property with a string no exceptions are thrown but facebook messenger shows no response message. Given what a huge platform FB Messenger is you would think this was a priority in the SDK but I see nothing about it.
if (turnContext.Activity.Type == ActivityTypes.Message)
{
try
{
if((turnContext.Activity.ChannelId == Channel.Channels.Facebook)|| (turnContext.Activity.ChannelId == Channel.Channels.Emulator))
{
string rsp = "{\"attachment\":{\"type\":\"template\",\"payload\":{\"template_type\":\"button\",\"text\":\"What do you want to do next?\",\"buttons\":[" +
"{\"type\":\"web_url\",\"url\":\"https://www.messenger.com\",\"title\":\"Visit Messenger\"}]}}}";
Activity reply = turnContext.Activity.CreateReply();
_logger.LogInformation(rsp);
//reply.Text = rsp; // display message as actual message to messenger
// reply.ChannelData = rsp; // fails request finishes on the MS bot service side, but nothing at all shows on messenger
reply.ChannelData = JsonConvert.DeserializeObject(rsp); // WORKS!
await turnContext.SendActivityAsync(reply);
.... // IN MY ORIGINAL POST THERE WAS AN ERROR IN THE JSON STRING and I got the full answer a minute later... see answer below.
My bad on this. The original post had an error in the rsp string but I also took a look at the sdk source and realized they wanted an object at ChannelData, not a string.... so I deserialized it and stuffed the object to channeldata and it started working. Few posts on this in SDK version 4 so hoping this helps someone. My wall needs some repair after me pounding my head against it all day. – Fred Covely just now
I'm developing a graphic user interface where the user can send a message to mutuple user using Twilio API in c#
I'm trying to bind a list view to the status of each number being sent and I also want to know the status of the message every time the user click on refresh list view
public void sendSMS(string ssid, string token , string fromNumber, List<string>TOnumbersList ,string msgBody )
{
TwilioClient.Init(ssid, token);
foreach (var toNumber in TOnumbersList)
{
var message = MessageResource.Create(
to: new PhoneNumber(toNumber),
from: new PhoneNumber(fromNumber),
body: msgBody,
provideFeedback: true,
statusCallback: new Uri("http://requestb.in/1jnk4451"));
ListViewItem items = new ListViewItem(message.To);//This show the number being sent to ( delivered number)
items.SubItems.Add(message.Status.ToString()); //Refresh the status WHERE number = message.To
items.SubItems.Add(message.ErrorCode.ToString());//Show error code in case
items.SubItems.Add(message.ErrorMessage); // In case error message show them
listView1.Items.AddRange(new ListViewItem[] { items });
}
}
Twilio API is doing the perfect job updating the status so everytime I go click the link I can see the status. as explained in this documentation Track Delivery Status of Messages in C#
But is It possible to bind a list view so it can be updated everytime the user click on refresh list view ?
Or what is the best way to dynamically show the message status from the URI http://requestb.in/1jnk4451? Maybe embedding a webpage would be better ?
Thank you
Twilio developer evangelist here.
Rather than using the RequestBin URL, if you provide a URL to your own application then you can write an endpoint that receives the status updates of the messages. That way you can store the status yourself and update the list view without having to loop through all the messages.
[Edit] In more detail:
When you send an SMS message with Twilio using the REST API you can set a statusCallback URL to receive updates about the message as it processes through from Twilio to the network and the device.
Twilio will make HTTP requests to this URL as the message goes through each state, the possible states being queued, failed, sent, delivered, or undelivered. Twilio sends a number of parameters as part of this request, some are general ones about the message and some are about the actual status.
To receive these requests you need to set up a web server. I'm not a C# developer I'm afraid, however we have a guide on how to set up a C# and ASP.NET MVC environment that can receive webhooks that should be able to help you there.
Let me know if this helps a bit more!
I am trying to use the Microsoft Bot Framework DirectLine API to read and add messages to existing conversations between other users and my bot. From what I've read I believe this should be possible when using the master-secret but it's just not working for me. I'm using a WebAPI to try and access two of my existing conversations (on Facebook & Skype) as follows:
[HttpPost]
[Route("remind")]
public string Remind()
{
var secret = System.Configuration.ConfigurationManager.AppSettings["secret"];
var uri = new Uri("https://directline.botframework.com/");
var creds = new DirectLineClientCredentials(secret);
DirectLineClient client = new DirectLineClient(uri, creds);
Conversations convs = new Conversations(client);
var conversationIDs = new string[] { "0000000000000000-0000000000000000", "00:0123456789abcdefghijklmnopqrstuvwxyz0123456789-A-_0123456798ABCDEF" }; // Existing Facebook & Skype conversations
// Send a message to each conversation:
foreach (var conversationID in conversationIDs)
{
Message message = new Message(conversationId: conversationID, fromProperty: "My Bot", text: "Hey dude, remember that thing!");
Console.WriteLine(message.Text);
convs.PostMessage(conversationID, message); // FAILS - This executes but doesn't do anything.
}
// Try reading the messages from a conversation (just to test if it's working):
string waterMark = null;
var set = convs.GetMessages(conversationIDs[0], waterMark); // FAILS - This fails with a 404 not found.
waterMark = set.Watermark;
return "Done :-)";
}
It fails silently calling PostMessage() and fails with a 404 for the GetMessages(). I seem to be doing the right thing, the bot is live etc and works very well in Facebook & Skype separately from the DirectLine API. It only works if I create a new conversation using the DirectLine API, I can then access its messages and post new messages to it.
This question sort of helps but doesn't quite tell me what to do to fix it:
Difficulty accessing messages in an existing conversation in Microsoft Bot Framework
Any help would be much appreciated.
Thanks
For security reasons, you can't use DirectLine to spy on messages from another conversation. For the scenario you describe (escalating to a human) there a number of different ways to approach this. One is to have your bot broker conversations between the accounts (i.e. Facebook End User <-> Your Bot <-> Facebook Support Person). Each is talking to the bot, and the bot passes the message through to the other user. (Could also be Facebook User <-> Your Bot <-> Skype User) Your bot would have to store last n messages to provide context. Alternatively, I've seen folks build their own customer support chat interface using direct line that sits on the far side. Hope this helps
I'm a newbie in iOS development. Recently, I tried to use moon-APNS to send push notification to my device. I followed every step in arashnorouzi.wordpress.com. And when I run my program and read the log, notification was successfully sent to APNS server, but I never receive notification on my device. What is possibly wrong? Is there some setting I should do on my device or the iOS application? I only change the device token, certificate path, password at the example code. Here is my code:
var payload1 = new NotificationPayload("b8bf91fcc66016a7bf96154f3c65c6c479385df98094394c2514682152c29968", "Message", 1, "default");
payload1.AddCustom("RegionID", "IDQ10150");
var p = new List<NotificationPayload> {payload1};
var push = new PushNotification(false, "D:\\certificate\\aps_development.p12","aswin123");
var rejected = push.SendToApple(p);
foreach (var item in rejected)
{
Console.WriteLine(item);
}
Console.ReadLine();
Anyone can help me? I really appreciate your answers.
Check did you done this:
enabled Push Notification of your app in the appID
check , does you getting token while you run the application