Ionic sending Parse push notification with attached url - c#

I've been busy with a new application based on ionic. It's a new environment so I have a lot to explore.
I'd walked into some problems and search over the whole internet to find a solution and couldn't find one solving my problem. So I hope one of you guys know a solution.
I am trying to send notifications to my device using parse. That works fine, but now I want to send an uri attached with it, so that I can open a specific page clicking on the notification that has been recievied.
The problem is that I have no clue how to correctly send an attached uri and recieve that uri on the device to do something with it.
I hope some of you knows a solution.
I'm using ASP.NET to send the notification with a working initialized client.
var parsePush = new ParsePush();
// sending to all with your own data
parsePush.Data = new Dictionary<string, object>
{
{"alert", txtMessage.Text},// this is replacement for parsePush.Alert
{"sound", "notify.caf"},// for ios
{"badge", "Increment"}// for ios notification count increment on icon
//{"category", "http://google.nl" }
};
parsePush.SendAsync().Wait();
For the ionic side I don't have an event to recieve the notification and work with it. I just get the notification and get redirected to the home page of the app.
Please inform me if there are unclear details.
Thanks a lot!

I fixed this problem by searching over the whole internet.
The first thing I did was uncommenthing the category in my parsePush.data on the server side (see code in the question). In the category I define the uri. The next thing I did was adding "ParsePushPlugin.on" to my app.js. Those event are used when a notification is recieved or opened.
I added this code to my app.js inside the .run -> $ionicPlatform.ready.
ParsePushPlugin.getInstallationId(function (id) {
alert(id);
storage.set('parseId', id);
}, function (e) {
alert('error');
});
ParsePushPlugin.on('receivePN', function (pn) {
alert('yo i got this push notification:' + JSON.stringify(pn));
});
//customEvt can be any string of your choosing, i.e., chat, system, upvote, etc.
ParsePushPlugin.on('receivePN:chat', function (pn) {
alert('yo i can also use custom event to keep things like chat modularized');
});
ParsePushPlugin.on('openPN', function (pn) {
//you can do things like navigating to a different view here
//alert('Yo, I get this when the user clicks open a notification from the tray');
$state.go(pn.category)
});
As you can see "ParsePushPlugin.on('openPn')" has pn as parameters which contains all the data from the recieved and opened notification. This notification also contains the "category (uri)" which is passed from the server side.

Related

DSharpPlus send an embed to a specific channel?

I'm new to working with discord bots and I was wondering if anybody knew a way to send embedded messages to specific channels. The only way I've found so far to send one is to use RespondAsync which just directly replies to whoever issues the command in the same channel. The purpose of my bot is to create automated link directories in read only channels and the command will just refresh them. Having trouble finding much Dsharpplus c# examples, and I'm terrible at making sense of documentation. Any help would be appreciated.
await ctx.RespondAsync(embed);
this is what I've been using to send my embeds for testing purposes, but like I said I'd like to send it in a way that it posts to a specified channel
You just need to get the DiscordChannel object of the channel(s) you want to send the embed. You can get the ID of the channel via right-click in Discord and "Copy ID"
DiscordChannel channel = await _client.GetChannelAsync(ID_OF_CHANNEL);
DiscordEmbedBuilder embed = new DiscordEmbedBuilder
{
Color = DiscordColor.SpringGreen,
Description = "Good to see you!",
Title = "Hello World"
};
await channel.SendMessageAsync(embed: embed);
The DiscordGuild class also has GetChannelAsync you can use.

How to disable button after single use in a Adaptive Cards

I am using Adaptive Cards in my LUIS agent. Once a user has filled in all the details and submits the card the submit button should get disabled to prevent duplicate usage of the button.
We also would like to know how to hide a button when displaying a nested Adaptive Card on a button click.
I tried validating the card using the input values made by the user but i am looking for a better and optimal solution for this
P.s working on bot framework v4 API
In a channel like Teams, your bot can call the update activity API and edit the card in the conversation history that way. Web Chat does not support updating or deleting activities out of the box, but if you fork the Web Chat repo you can modify it to do whatever you want. This is essentially the same as creating your own Direct Line client while using Web Chat as a starting point.
For clarity, I want to briefly mention that Web Chat is not really a channel. Direct Line is the channel, and Web Chat is a Direct Line client. The client application is what is ultimately responsible for rendering cards and handling their interactivity.
There is a way to effectively disable Adaptive Card submit actions in any channel using bot state. If you put identifying information in the submit action's data, then you can have your bot remember that the button has already been clicked. If you make sure the bot doesn't do anything when the button is clicked again then it's effectively disabled even though it doesn't look any different.
If you're interested in more Adaptive Card functionality becoming available as a NuGet package, please show some support for my Bot Builder Community idea. If you would like to understand more about using Adaptive Cards with the Bot Framework in general then have a look at my latest blog post.
In webchat, hiding/disabling submit button can be handled in "Incoming Activity" event of Azure bot. You can get 'your_submit_button_id' from JSON file of adaptive card.
const store = window.WebChat.createStore(
{},
function (_ref) {
const dispatch = _ref.dispatch;
return function (next) {
return function (action) {
if (action.type === 'DIRECT_LINE/CONNECT_FULFILLED') {
dispatch({
type: 'WEB_CHAT/SEND_EVENT',
payload: {
name: 'webchat/join',
value: { language: window.navigator.language }
}
});
}
if (action.type === 'DIRECT_LINE/INCOMING_ACTIVITY') {
const event = new Event('webchatincomingactivity');
event.data = action.payload.activity;
/* hiding/disabling button code starts here */
if(event.data.value!=undefined && event.data.value.id=='your_submit_button_id')
{
var btnArr=document.getElementsByClassName("ac-pushButton");
btnArr[btnArr.length-1].style.display='none';
//btnArr[btnArr.length-1].disabled = true;
}
window.dispatchEvent(event);
}
return next(action);
};
};
});

Any downsides to replacing REST endpoints with SignalR?

I'm building a fairly simple single page app. It's basically a list of items, where each item has some details, an activity log, and a current status along with some buttons to trigger actions on the server to advance the status along a workflow.
It was originally written using MVC and REST/Web API but I got stuck on the problem of keeping concurrent users up to date. For example, if User A adds an item, we want the list on User B's screen to now update to include it.
To solve this I looked into SignalR which works great. But I had a problem.
When adding an item (using POST) the callback adds the item on the requesting client. This is fine.
I then triggered a SignalR broadcast on the server to tell all clients about the new item. This worked fine except the local client, who now has 2 items.
I was looking into filtering the duplicate id client-side, or sending the connection id with the POST, then broadcast to all clients except the requester but it seems a bit needlessly complicated.
Instead I'm just doing this.
public class UpdateHub : Hub
{
public void AddNewItem(NewItem item)
{
// and some server-side stuff, persist in the data store, etc
item.trackingID = new Guid();
item.addLogEntry("new item");
// ...
dataStore.addItem(item);
// send message type and data payload
Clients.All.broadcastMessage("add", item);
}
}
It seems a lot simpler to just get rid of all the REST stuff altogether, so am I missing anything important?
It'll run on an intranet for a handful of users using IE11+ and I guess we do lose some commonly-understood semantics around HTTP response codes for error handling, but I don't think that's a huge deal in this situation.
In order to solve duplicate you can try to use Clients.Others inside Hub class, or AllExcept(id) if you not in the Hub class.
Clients.Others.broadcastMessage("add", item);
In your case using SignalR shouldn`t have any downsides.

How would I only allow only certain messages to be set users [NODE.JS]

I am working on a mutliplayer game and decided to use NodeJS aspart of the system.
The nodeJS is linked to m c# game emulator via TCP.
However how would I send messages to certain user ID?
Each individual user in the database is sided by a unique user ID (E.G 1)
How can I do this so if a user in game does a certain thing and that sends a message
from Node ONLY TO THEM.
Since I can't run node on the same port as my cms (Port 80).
I need a method in which I can use PHP to pull the ID or something.
Use as Jquery and 'GET'? I'm suck.
By message I mean data such as sending a javascript window.
Options available:
JQuery
Javascript
PHP
Node
I thought of a method were the user id is presented within a div through a parameter in PHP (E.G $ID) and then javascript checked against the div and the message to see if the ids matched. Then within the message the users ID would be included, then somehow I could split the message? so its "","" (ID,MESSAGE)
Code:
var socket = io.connect('http://dev.com');
socket.on('field', function (data) {
if ($("#userid").text().indexOf(data) > -1)
{
window.alert('lol');
console.log(data);
$("#field").html(data);
}
else
{
window.alert("Something has gone wrong with the node server...");
}
});
It didn't work.
THE PAGE:
THE C#:
THE NODE:
Based on your response in the comments:
Inside the messages are just html that node sends to the page via a Node HTTP server. The messages aren't big just little things like "window.open("google.com");. Messages are only triggered if a user clicks a certain thing within game and no.
It sounds to me like what you really want is some sort of RPC. There's a solid NPM module called Socket.IO which wraps all this up nicely for you. Fire an event, it can be handled server-side, and any callback data gets sent back to the client.
http://socket.io/docs/

SignalR not adding server callbacks

When every I attempt to add a new server callback function I cannot seem to get the callback to show up in the $.connection server callback list.
What do I need to do to refresh the javascript that SignalR produces and sends to the client with the latest list of server callbacks.
I would think that I should be able to just add a server callback for the client to call and rebuild my app and fire up a new instance of Google Chrome and the newly added server callback would be in the list of available callbacks on the client.
For example here is exactly what I've done.
1.) A client joins a group and everyone is notified.
public override Task OnConnected()
{
string pid = this.Context.QueryString["pid"],
uid = this.Context.QueryString["uid"],
ispro = this.Context.QueryString["ispro"];
Groups.Add(this.Context.ConnectionId, pid);
return Clients.Group(pid).joined(new cmsg(Context.ConnectionId, UtilCommon.GetUserMini(new Guid(uid), bool.Parse(ispro))));
}
2.) On the client the joined function is called from the server
this.collaborateHub.client.joined = function (cmsg) {
//
that.chatBox.addAttendee(cmsg);
//let the new attendee know about you
if (cmsg.cnnid !== that.chatBox.getMeAttendee().cnnid) {
that.chatBox.getMeAttendee().newbieid = cmsg.cnnid;
debugger
this.server.addMeNewbie(that.chatBox.getMeAttendee());
};
};
3.) Now, if someone joined and it was not the user of the currently opened window, that means the someone how just joined is someone other than myself, so I need to call the server back and notify the newly joined user to add me to their user list. I stead of having to keep up with the currently signed on users to the given group in a database, I am just using every signed on client of the group as a distributed database and let them manage their own info.
So, I need to call the server callback named addMeNewbie; however, this callback function is not available in the list.
public Task addMeNewbie(cmsg cmsg) {
return Clients.Client(cmsg.newbieid).addCurrAttendee(cmsg);
}
Here is a snapshot of the client side in debug mode
4.) And finally here is the client side callback that i need the server to call so that the newly joined group member can update their list of current group members.
this.collaborateHub.client.addCurrAttendee = function (cmsg) {
debugger
that.chatBox.addAttendee(cmsg);
};
I would think that I should be able to add as many server callbacks as I want and they should show up on the next build and restart of a new instance of Google Chrome; however, this is not the case. What do I need to do to get newly added server callbacks to show up in the available server callbacks on the client side?
This doesn't make since to me, but I am thinking maybe this is a cashing issue or something?
The only callback that is available is the one shown in the snapshot provided. At this time I've only got two callbacks, the one that you see in the snapshot and the one that is not visible.
Somewhere along the way I created a signalr-hubs.js file from the generated JavaScript file that can be retrieved by http://localhost:3250/signalr/hubs and was adding new server functions to my hub but not updating the signalr-hugs.js file.
At this point every time I add a new server callback I retrieve the newly generated proxy by placing this url http://localhost:3250/signalr/hubs into the browser, coping the code, and then updating my signalr-hubs.js file.

Categories