How to read the particular SMS message in univarsal windows phone 10 - c#

In my project I want to read the particular SMS message and delete that message it possible in universal windows phone 10..
Is is posible using Chat Message Access in manifest file?

You can use the chat messages api to access the SMS messages of your device. Using the ChatMessageStore you will be able to create/delete the messages but it might not be what you really want. The chat message api is more designed to create messaging application like WhatsApp.
If the message you want to receive is an app-directed message you can intercept it before it reaches the ChatMessageStore. The universal windows platform is exposing a new (restricted) API to intercept the messages before they reach the store using custom filtering rules. You can have a look at this sample. It is using the newest SmsMessageReceivedTrigger background task trigger.
Since this API is restricted, you will have to request the autorisation to use from Microsoft before being able to publish such an app to the store
Here is a sample about how to use the SmsMessageReceivedTrigger with the background task entry point and registration
public async void Run(IBackgroundTaskInstance taskInstance)
{
var smsDetails = taskInstance.TriggerDetails as SmsMessageReceivedTriggerDetails;
// consume sms
var from = smsDetails.TextMessage.From;
var body = smsDetails.TextMessage.Body;
// we acknoledege the reception of the message
smsDetails.Accept();
}
static IBackgroundTaskRegistration Register()
{
var taskNameAndEntryPoint = typeof(SmsInterceptor).FullName;
var task = BackgroundTaskRegistration.AllTasks.Values.FirstOrDefault(x => x.Name == taskNameAndEntryPoint);
if(task != null) return task;
var filterRule = new SmsFilterRule(SmsMessageType.App);
filterRule.SenderNumbers.Add("111111111");
filterRule.SenderNumbers.Add("222222222");
var filterRules = new SmsFilterRules(SmsFilterActionType.AcceptImmediately);
filterRules.Rules.Add(filterRule);
var taskBuilder = new BackgroundTaskBuilder();
taskBuilder.Name = taskNameAndEntryPoint;
taskBuilder.TaskEntryPoint = taskNameAndEntryPoint;
taskBuilder.SetTrigger(new SmsMessageReceivedTrigger(filterRules));
return taskBuilder.Register();
}
Since it is using a restricted API, you will have to add the following restricted capability to your appx manifest
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
xmlns:r="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
IgnorableNamespaces="uap mp r">
<Capabilities>
<r:Capability Name="cellularMessaging" />
</Capabilities>
</Package>
You will find a complete sample here
If you want to use the ChatMessageStore API, you can have a look at this sample which should be a good start.

Related

Why an installed app is not listed by Ms Graph API?

I am trying to upgrade an app which belongs to a chat. If the app is not installed, below code successfully install it:
await graph.Chats["19:7f...3#thread.v2"].InstalledApps
.Request()
.AddAsync(teamsAppInstallation);
But once the app is added, below code shows zero entries:
var installedApps = await graph.Chats["19:7f...3#thread.v2"].InstalledApps.Request().GetAsync();
I was expecting to see my app there. My target is to call Upgrade() for the app, because it should allow me to add ConversationReferences in one of the event functions (e.g. OnTurnAsync), that will allow me to send proactive message to the chat. Am I doing something wrong?
Permissions for an application are set:
TeamsAppInstallation.ReadWriteSelfForChat.All
TeamsAppInstallation.ReadWriteForUser.All
The authentication with the Graph API is done successfully, as I can create a chat, list channels etc.
https://login.microsoftonline.com/botframework.com/oauth2/v2.0/token
data:
grant_type=client_credentials&client_id={ MS_APP_ID_ENC }&client_secret={ MS_APP_PASS_ENC }&scope=https%3A%2F%2Fgraph.microsoft.com%2F.default
I was adding the app to the chat both manually and with C# request:
var teamsAppInstallation = new TeamsAppInstallation {
AdditionalData = new Dictionary<string, object>()
{
{
"teamsApp#odata.bind", "https://graph.microsoft.com/v1.0/appCatalogs/teamsApps/0c...68/"}
}
};
var installedApp = await graph.Chats["19:7f...3#thread.v2"].InstalledApps. Request().AddAsync(teamsAppInstallation);
And the app was added. It can be used in the chat.
It turned out that I've used wrong application permissions. Even though TeamsAppInstallation.ReadWriteSelfForChat.Al is listed in the docs, I needed to add TeamsAppInstallation.ReadWriteForChat.All to make it working.

Unable to publish advertising data for BLE in wpf application

I am working on a wpf application where I need it to work as a publisher. So I want to publish some data and there will be other devices listening to this data. I am trying to send this data with advertisement and have been following This Link but I am not able to even detect this application in my iPhone app who is supposed to read this published data.
I am trying to add the data as following:
private BluetoothLEAdvertisementPublisher publisher;
this.publisher = new BluetoothLEAdvertisementPublisher();
ushort id = 0x1234;
var manufacturerDataWriter = new DataWriter();
manufacturerDataWriter.WriteUInt16(id);
var manufacturerData = new BluetoothLEManufacturerData
{
CompanyId = 0xFFFE,
Data = manufacturerDataWriter.DetachBuffer()
};
publisher.Advertisement.ManufacturerData.Add(manufacturerData);
publisher.Start();
Edit:
Do I need to create some characteristics too? I found a tutorial on MSDN about this and using smaple code I am able to send the characteristics but I am still not able to advertise my custom data to other devices.

How to use azure notification hub tags for push messages in UWP apps

I want to send push messages to apps in specific channels, like "en-us" and "fr-fr" to localize the push notifications.
First i followed this tutorial, and it all worked:
https://learn.microsoft.com/en-us/azure/notification-hubs/notification-hubs-windows-store-dotnet-get-started-wns-push-notification
the working registration there is:
var result = await hub.RegisterNativeAsync(channel.Uri);
But thats to send one message to all clients. Then i followed this tutorial:
https://learn.microsoft.com/en-us/azure/notification-hubs/notification-hubs-windows-notification-dotnet-push-xplat-segmented-wns
and from what i could extract from that confusing mix with uwp code is this line:
var hub = new NotificationHub("AppName", "endpoint");
const string templateBodyWNS = "<toast><visual><binding template=\"ToastText01\"><text id=\"1\">$(messageParam)</text></binding></visual></toast>";
var result = await hub.RegisterTemplateAsync(channel.Uri, templateBodyWNS, "simpleWNSTemplateExample", new string[] { "en-us" });
Result also gives me a valid registration.
Then i tried to test it using the azure notfication hub console (that worked with the previous step to send it to all clients:
which resulted in the app getting the notification (it does not filter for "en-us").
Then i tried to put "en-us" in the "send to tag expression":
With that, no toast message arrives.
Then i tried to send the message via Microsoft.Azure.NotificationHubs package.
This code works:
NotificationHubClient Hub = NotificationHubClient.CreateClientFromConnectionString(endpoint, name);
string toast = #"<?xml version='1.0' encoding='utf-8'?>
<toast>
<visual><binding template='ToastText01'>
<text id='1'> Test message </text>
</binding>
</visual>
</toast>
";
var result = await Hub.SendWindowsNativeNotificationAsync(toast);
A Toast Message arrives. But as soon as i change the last line to:
var result = await Hub.SendWindowsNativeNotificationAsync(toast, "en-us");
Nothing arrives.
So Notification Hub is successfully linked to the client via WNS, but using tags does not work at all. What do i do wrong?
Okay i figured it out, here for anyone with the same question:
First, as someone else might get confused with this as well, is that we need to understand that the concept of defining the Push Templates is different from how FCM (for Android) works. In FCM, you define the layout and content of the push message server-side.
In UWP, it happens client side when using tags. When designing a toast you can put variables inside it, which then get filled by the serverside.
This is the working code.
Client side:
var hub = new NotificationHub("Hubname", "endpoint");
string toast = #"<toast>
<visual><binding template='ToastGeneric'>
<text id='1'>$(Title)</text>
<text id='2'>$(Message)</text>
<text placement='attribution'>via SMS</text>
</binding>
</visual>
</toast>
";
var result = await hub.RegisterTemplateAsync(channel.Uri, toast, localizedWNSTemplateExample", new string[] { "myTag" });
Serverside:
NotificationHubClient Hub = NotificationHubClient.CreateClientFromConnectionString(endpoint, name);
Dictionary<string, string> templateParams = new Dictionary<string, string>();
templateParams["Title"] = "Title here";
templateParams["Message"] = "Message here";
await Hub.SendTemplateNotificationAsync(templateParams, "myTag");
And from the web you can send messages with the "Custom Template" Platform:
Not sure if "Custom Template" can also be used with android and iOS as well though. It would be awesome.

Microsoft Bot Framework DirectLine Can't Access Conversations

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

PushSharp:Android GCM Push Notification received without push message

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)
);

Categories

Resources