How to leave the chat channel? - getstream-io

I'm building a client with stream-chat-react for chat client with stream chat API. I implemented setUser, create a channel, but I'm struggling with leaving a channel.
I'm implementing a chat on React web app. I've tried with 'stopWatching()` method, but it's not working for my case.
const ControlBar = withChatContext(({ client }) => {
const leaveChannel = async () => {
try {
await channel.stopWatching()
logger('stop watching')
} catch (error) {
logger('stop watching error > ', error)
}
}
...
}
How can I make just getting out of the one channel and disappeared in <ChannelList />

I've found a workaround to edit the permission of channel type. You can connect to the Stream dashboard and go to Chat Overview. then, you can edit the channel type, clicking e.g. messaging. You can modify the permissions of it.
...,
# Add UpdateChannelMembers permission
{
"action": "Allow",
"name": "Users can leave channels",
"resources": [
"UpdateChannelMembers"
],
"roles": [
"user"
],
"owner": false,
"priority": 50
},
...

Related

Azure Static Web App Role Functions Not Working

I've made an attempt to get Azure Static Web Apps with customized Roles function to work in my environment just as specified by: https://learn.microsoft.com/en-us/azure/static-web-apps/assign-roles-microsoft-graph
Everything seems to work as expected but when visiting the page restricted by a specific role the API doesn't seem to be assigning the expected role.
I've modified the API and removed all the logic to assign a role to everyone logging in and still doesn't work. Here's the modified code:
const fetch = require('node-fetch').default;
module.exports = async function (context, req) {
const user = req.body || {};
const roles = [];
roles.push('superuser');
context.res.json({
roles
});
}
Here's my staticwebapp.config.json file:
{
"auth": {
"rolesSource": "/api/GetRoles",
"identityProviders": {
"azureActiveDirectory": {
"userDetailsClaim": "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name",
"registration": {
"openIdIssuer": "https://login.microsoftonline.com/44263d43-a2f0-45a8-8f55-9b100ecfb4dc",
"clientIdSettingName": "AAD_CLIENT_ID",
"clientSecretSettingName": "AAD_CLIENT_SECRET"
},
"login": {
"loginParameters": ["resource=https://graph.microsoft.com"]
}
}
}
},
"routes": [
{
"route": "/secured/*",
"allowedRoles": ["superuser"]
},
{
"route": "/admin/*",
"allowedRoles": ["administrator"]
},
{
"route": "/contributors/*",
"allowedRoles": ["contributor", "Contributor"]
}
],
"responseOverrides": {
"401": {
"redirect": "/.auth/login/aad?post_login_redirect_uri=.referrer",
"statusCode": 302
}
}
}
I've tried changing the order of the config file. My last attempt before posting was to remove all logic and just assign everyone the 'superuser' role.
Everyone can login successfully & pre-defined roles work like a charm but no one ever gets the 'superuser' role.
I'm trying to figure out what I'm doing wrong or has Azure Static Web Apps changed so that this code just won't work like it did a year ago?
Thank you help in advance.

Amazon SP-API can't assume role of myself?

I'm trying to connect to the Amazon Selling Partners API (SP-API) using the node.js library and am coming across an extremely odd error which seems to be telling me I can't assume my own role?
CustomError: User: arn:aws:iam::11111:user/bob is not authorized to perform: sts:AssumeRole on resource: arn:aws:iam::11111:user/bob
I'm fairly new to AWS but I'm pretty sure that this inline policy for the user should be sufficient for what I'm trying to do, I've even made it work for all resources rather than just the SellingPartners role I'd previously created:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": "sts:AssumeRole",
"Resource": "*"
}
]
}
Here's my full code in case it helps:
const SellingPartnerAPI = require('amazon-sp-api');
(async() => {
try {
let sellingPartner = new SellingPartnerAPI({
region:'na', // The region to use for the SP-API endpoints ("eu", "na" or "fe")
refresh_token:'xxxxxx', // The refresh token of your app user
credentials:{
SELLING_PARTNER_APP_CLIENT_ID:'xxxxx',
SELLING_PARTNER_APP_CLIENT_SECRET:'xxxxx',
AWS_ACCESS_KEY_ID:'xxxx',
AWS_SECRET_ACCESS_KEY:'xxxxx',
AWS_SELLING_PARTNER_ROLE:'arn:aws:iam::11111:user/bob'
}
});
let res = await sellingPartner.callAPI({
operation:'getOrders',
endpoint:'orders'
});
console.log(res);
} catch(e) {
console.log(e);
}
})();
The ARN arn:aws:iam::11111:user/bob describes a User not a role.
It should probably be something like arn:aws:iam::11111:role/your-role-name if the client expects a Role ARN.

Send Notification To Subscriber Users

I'm developing forexsignals App and i want to send notification to users who subscribe to specsfic currency when inserted in firebase
i Have more then 50 SwitchListTile and should users select ( subscribe to currency)
to get notify.
im using FCM
thank you
This problem can be solved using three simple steps:
Step 1: Setup and configure Firebase core and Firebase messaging.
I Assume you have done it already
Step 2: Subscribe to the topic when the boolean of the switch is true and unsubscribe when boolean is false
Example:
SwitchListTile(
title: const Text(currency),
value: _lights,
onChanged: (bool value) {
setState(() {
_lights = value;
if(value){
await FirebaseMessaging.instance.subscribeToTopic(currency);
}else{
await FirebaseMessaging.instance.unsubscribeFromTopic(currency);
}
});
},
);
Step 3: On the Server side :
Have a post request of JSON on: https://fcm.googleapis.com/fcm/send
with json as :
{ "notification": { "body": "Message..",
"title": "Your Title",
"color":"#fabea7",
"image": "image url"
},
"priority": "high",
"to":"/topics/currencyyouwant"
}

actions-on-google Account Linking Signin status is "ERROR" always

I got this sample code from the docs of actions on google account linking with google account. The signin.status is always "ERROR". I have tried on actions console simulator, google assistant app on my phone and on a google home mini with personal results on. But the result is the same in all cases.
const express = require('express');
const bodyParser = require('body-parser');
const {actionssdk, SignIn} = require('actions-on-google');
const app = actionssdk({
// REPLACE THE PLACEHOLDER WITH THE CLIENT_ID OF YOUR ACTIONS PROJECT
clientId: <client_id>,
});
// Intent that starts the account linking flow.
app.intent('actions.intent.MAIN', (conv) => {
conv.ask(new SignIn('To get your account details'));
});
// Create an Actions SDK intent with the `actions_intent_SIGN_IN` event.
app.intent('actions.intent.SIGN_IN', (conv, params, signin) => {
console.log(signin)
if (signin.status === 'OK') {
const payload = conv.user.profile.payload;
conv.ask(`I got your account details, ${payload.name}. What do you want to do next?`);
} else {
conv.ask(`I won't be able to save your data, but what do you want to do next?`);
}
});
app.intent('actions.intent.TEXT', (conv) => {
conv.close("bye");
})
//Run server
const expressApp = express().use(bodyParser.json());
expressApp.post('/', function(req,res){
app(req,res);
});
expressApp.listen(8080,() => {console.log("listening")});
This is the signin object I'm being returned
{ '#type': 'type.googleapis.com/google.actions.v2.SignInValue',
status: 'ERROR' }
EDIT
My actions.json is as follows
{
"actions": [
{
"description": "Default Welcome Intent",
"name": "MAIN",
"fulfillment": {
"conversationName": "fulfilment function"
},
"intent": {
"name": "actions.intent.MAIN",
"trigger": {
"queryPatterns": [
"talk to Care Cat"
]
}
}
},
{
"description": "Everything Else Intent",
"name": "allElse",
"fulfillment": {
"conversationName": "fulfilment function"
},
"intent": {
"name": "actions.intent.TEXT"
}
}
],
"conversations": {
"fulfilment function": {
"name": "fulfilment function",
"url": <url>
}
},
"locale": "en"
}
Could it be because it is still a test app which is not published yet?
Can someone help me with this?
In your Google Cloud Platform Account, check your IAM settings and enable the Dialogflow API Admin
Documentation for more details: https://cloud.google.com/dialogflow/docs/access-control

Route to the url when user clicks on notifications in pwa, angular 6 and web-push in Node.JS

I am working on pushing the notifications in PWA using SwPush in Angular6. For this I am using #angular/service-worker. I am able to send the notifications from node server. But when I click on the received notification, it is not able to route the desired url. I am using web-push module in node.js, and this is the payload:
"payload": {
"title": "Sample Notification",
"actions": [
{
"action": "opentweet",
"url":"https://pwa-sw-push-notifications.firebaseapp.com",
"title": "Open tweet"
}
],
"body": "A sample data to check the notification availability!",
"dir": "auto",
"icon": "https://pwa-sw-push-notifications.firebaseapp.com/assets/icons/icon-72x72.png",
"badge": "https://pwa-sw-push-notifications.firebaseapp.com/assets/icons/icon-72x72.png",
"lang": "en",
"url": "https://pwa-sw-push-notifications.firebaseapp.com",
"renotify": true,
"requireInteraction": true,
"tag": 926796012340920300,
"vibrate": [
100,
50,
100
],
"data": {
"url": "https://pwa-sw-push-notifications.firebaseapp.com",
"favorite_count": 0,
"retweet_count": 0
}
}
I am using
var webPush=require('web-push');
//sub is userSubscriptionObject to send the notifications to subscribed user browser.
webPush.sendNotification(sub, JSON.stringify(payload))))
In angular,
export class IndexComponent implements OnInit {
users: any = [];
constructor(
private http: HttpClient,
private router: Router,
private swPush: SwPush) {
console.log('this is index');
}
ngOnInit() {
this.getCoins();
}
subscribeNotifications(){
this.swPush.requestSubscription({
serverPublicKey: "BMW3STH0ODuNdhFVAZIy8FUDEwt2f8LLpWBiBnz8WE0_558rZc4aLbZUD9y-HxMlfCtyE5OD0mk3xa2oFJZu5n0"
}).then(sub => {
console.log("Notification Subscription: ", sub);
this
.http
.post('https://e1a2e469.ngrok.io/sub/subscribeNotifications', sub);.subscribe(
() => {
console.log('Sent push subscription object to server.');
},
err => console.log('Could not send subscription object to server, reason: ', err)
);
})
.catch(err => console.error("Could not subscribe to notifications", err));
}
unsubscribeNotifications(){
this.swPush.subscription.pipe(take(1)).subscribe(subscriptionValue=>{
console.log('this is un subscription', subscriptionValue);
this
.http
.post('https://e1a2e469.ngrok.io/sub/unsubscribeNotifications', subscriptionValue);
.subscribe(
res => {
console.log('[App] Delete subscriber request answer', res)
// Unsubscribe current client (browser)
subscriptionValue.unsubscribe()
.then(success => {
console.log('[App] Unsubscription successful', success)
})
.catch(err => {
console.log('[App] Unsubscription failed', err)
})
},
err => {
console.log('[App] Delete subscription request failed', err)
}
);
});
}
sendNotifications(){
console.log('subscribeNotifications')
this
.http
.post('https://e1a2e469.ngrok.io/sub/sendNotifications', null).subscribe(res=>{
console.log('subscribed successfully');
});
}
}
My intention is, when user clicks on the notification it is supposed to route to
https://pwa-sw-push-notifications.firebaseapp.com.
I have tried giving this URL in different parameters in the above object like actions[0].action.url URL data.url and nothing worked. So I am confused where to give the URL to make it possible. Could anyone help me out?
Thank you.
There's nothing wrong with your payload, as far as I can see. The payload is just a data which is delivered to your browser, on your browser side you need to implement notificationClick handler in order to process the payload data i.e., navigating to the desired URL. A simple notifictionClick handler can be implemented in service worker as follow:
this.scope.addEventListener('notificationclick', (event) => {
console.log('[Service Worker] Notification click Received. event', event);
event.notification.close();
if (clients.openWindow && event.notification.data.url) {
event.waitUntil(clients.openWindow(event.notification.data.url));
}
});
For reference check out the links below:
https://github.com/angular/angular/issues/20956#issuecomment-374133852
https://medium.com/google-developer-experts/a-new-angular-service-worker-creating-automatic-progressive-web-apps-part-2-practice-3221471269a1

Resources