How to destroy connection in Channel API GAE (python)? - google-app-engine

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

Related

How do I refresh the token in a cometd client talking to a Salesforce Platform EventBus?

I'm using cometd to listen to platform events generated in Salesforce. My cometd client configuration code looks like
this.client.configure({
url: `${this.org.instance_url}/cometd/46.0`,
requestHeaders: {
Authorization: `Bearer ${salesforceToken}`
},
appendMessageTypeToURL: false
});
where the salesforceToken is obtained using the refresh token. This all works fine for a while but if there are no events for a considerable period of time (anecdotally anywhere between 6-24 hours), then my client seems to expire and no events are received. If I refresh the token and restart my listener, things start working again.
Is there a way to keep the listener active other than writing some sort of timer to restart the process every few hours after inactivity ?
You do not have to refresh the token again
Whenever there is no activity on the channel, the server closes the connection after a specific time.
In that time client receives a 403 (Unknown client) status code, and the client has to handshake again withing 110 seconds.
By default, CometD tries to reconnect without any user interaction and If the client doesn't reconnect within the expected time, the server removes the client's CometD session.
Once the connection gets reconnect, all the channel subscriptions will be removed by ComedD, and we have to subscribe to the channel again in order to receive events.
In order to do so, we have to make use of meta/Handshake callback to resubscribe to the channel again.
see https://developer.salesforce.com/docs/atlas.en-us.api_streaming.meta/api_streaming/using_streaming_api_client_connection.htm, paragraph "After Invalid Authentication"
"Streaming API regularly validates the OAuth token or session ID while the client is connected. If client authentication is not valid, the client is notified with the 401::Authentication invalid error and an advice field containing reconnect=none. After receiving the error notification in the channel listener, the client must reauthenticate and reconnect to receive new events."

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.

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.

How to use GAE channel API when there are network disconnections ?

I want to use the Google App-Engine Channel API and send messages from server to client.
I'am worried about possible network disconnections.
What's happen by example if the client is not reachable from the server during a certain time ?
Is there a error message on server side ?
I saw that we can configure a special url for disconnection (/_ah/channel/disconnected/) but when this url is called? I think it's only when the disconnection is called using a function on client-side ?
My concern actually is : what if the client miss a important message of update ? Should i manage a acknowledgement for each message sent by the channel API ? (ex : rest call after each message sent ) ?
When the client come back to life (reconnection to the network), i will have to sent again all waiting messages ?
Thanks for your return if you already have implemented something similar.

GAE Channel API message broadcast to only one client?

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.

Resources