GAE Channel API message broadcast to only one client? - google-app-engine

I'hv been trying to learn the Google App Engine's Channel API lately.
I tried to make a simple chat app, but I am reaching problems.
This is generally what i have done.
server opens a static channel:
token = channel.create_channel('bigboys')
client js connect to channel with:
var channel = new goog.appengine.Channel(token)
I am not using Google App Engines users. I don't want clients to have to login.
So my problem is, the chat app doesn't really work, only one client can join the channel. I know there is a one client ID per channel rule. So how do I support multiple clients in one "chat room"?

Think of a channel being the connection between one client (browser) and your server.
If you have a chatroom, you'll need a channel for each client. You'll need something on the server side to keep track of all the clients in the chatroom, and the channel for each client. When you send a message, you'll need to send it on every client channel in the chatroom.

Related

how can I send emails from react using sendinblue?

I am working in React applications (using the .net core in the back-end)
I have to send emails from the client side , we have to use sendinblue instead of mailgun , I need your help
You should not send emails from the client side.
Consider that in doing so, you're going to expose your API Key to any client, leading to a severe vulnerability for your application (anyone could impersonate you and send emails as if they were you).
In order to really make that work, you should perform an AJAX request to your server and there, connect to the Sendinblue API and make the request to send the email. In this case, the API Key could be safely stored in your server.

payment gateway using socket.io and nodejs

I am developing a payment gateway (with 2 factor authorization, 2FA) with node/express for server side and angular js for client side.
The communication from client --> server can be done via a POST request but I want the communication from server --> client to happen via socket.io.
Now for new user who initiates a payment, a POST request will be sent from the client to server, data will be processed and a response will be sent back. For a very very specific reason, the response cannot be sent as part of the res in the received POST request.
app.post('/receive', function(req,res){
data = req.body
res.send('success')
// do something with the data
// Details regarding 2FA will be sent later via socket.io
}
After some processing, data will be sent to the client regarding 2 factor authorization.
io.on('2fa', {name:name, oneTimePassword:qwerty //and additional details})
I can listen to the channel 2fa from the client side, but every message emited on this will go to all the clients. I need a way to send a message to specific clients only who initiate that particular payment process.
Each transaction will be encrypted using ECDH. A UUID will be available for the transaction, initiating customer as well as the order number for which the payment is being done.
Appreciate any guidance for the above.
Socket.io has rooms. If you want, let's say, only the buyer and the seller to hear about the authentication result, put them into a room and emit your messages to the room itself. The client side won't change. You just socket.emit from the client to the server and the server will put the client into a room with all other appropriate parties and all the subsequent communication will only be emitted to the room instead of the channel 2fa.
This is from an html5 multiplayer game I developed, when the client joins a game room, this is what happens on the server side:
socket.on('joingame', function(data){
if(livingplayers[data.room] && livingplayers[data.room][data.id]){
socket.emit('joinfail', 'That name is taken');
} else {
socket.join(data.room);
socket.emit('joingame', data);
}
});
So, as you can see here, I join the client into the game, and I responded from the same channel and I informed the client that he successfully joined the game and on the server side I put the client into the room he joined. Any subsequent in-game actions will be broadcasted only to the room that the client just joined here.

How to destroy connection in Channel API GAE (python)?

I am creating a channel using channel api on app server using
channelId = channel.create_channel('mychannel')
now I want to destroy this channel. How can I do this ?
Channel Token expires in 2 hours by default. You don't explicitly get to delete a channel from server side, however, from the javascript side you can easily call a close() method

Receive slack bot messages via requests to external URL

Is it possible to receive direct messages on behalf of a slack bot via POST requests to a certain domain?
I want to have an endpoint in Google App Engine that receives incoming direct messages from Slack via POST requests, and posts messages back via the API. Is it possible?
You can use the new Events API. Create a bot, subscribe to message.im events, and set your endpoint as the callback URL
You just need to set up an "outgoing webhook"in slack and point it to whatever endpoint you need on your GAE server. In order to respond just use an "incoming webhook" to receive the answer.

What is the subscription stanza should be sent from my .net app to get XMPP notification from GAE app

Quick question: What is the subscripiton stanza should sent from my .net app to GAE app.
Background is :
I want to have a google app engine app act as a Web end point which receives notifications from Google Mirror SDK by JSON over HTTP and relays notification back to the subscribed XMPP clients. From Google App Engine, it sends invitation and sends messages that can be seen from Google Talk client on my windows system. I want to make my .net app similar to Google talk client, i'm trying with agXMPP library, after sending subscription stanza, it throws exception and disconnects the connection.
What is the correct subscription stanza i should send?
I'm sending:
<iq to="user_name#gmail.com" id="agsXMPP_1" type="set">
<subscribe xmlns="google:push">
<item from="test_appid.appspot.com" channel="test_appid.appspot.com" />
</subscribe>
</iq>
Thanks
I tried myself and figure it out. Just accept the invitation and send IQ object like this after opening the connection:
IQ iq = new IQ();
Jid jid = new Jid("app-id#appspot.com");
iq.To = jid;
iq.From = _bareJid;
XmppCon.Send(iq);
It worked.

Resources