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"
}
Related
I have a TEAMS node.js bot running locally (with ngrok). I receive messages from TEAMS client and echo works
context.sendActivity(`You said '${context.activity.text}'`);
Now I want to send a 1to1 message to this user, but I receive
Error: Authorization has been denied for this request
when creating a conversation.
My code:
var sUserId = "29:1shb_5I6CkkerBVq4qPqcv5dGwDfkXx11Jbjc1UnGCIv"
var sServiceUrl = "https://smba.trafficmanager.net/emea/";
var sTenantId = "942369d2-208e-438b-894c-0d0e1510cf61";
var credentials = new BotConnector.MicrosoftAppCredentials({
appId: "xxxxxxx",
appPassword: "yyyyyyyy"
});
var connectorClient = new BotConnector.ConnectorClient(credentials, { baseUri: sServiceUrl });
const parameters = {
members: [ { id: sUserId } ],
isGroup: false,
channelData:
{
tenant: {
id: sTenantId
}
}
};
var conversationResource = await connectorClient.conversations.createConversation(parameters);
// I get the error here, next is not executed
await connectorClient.conversations.sendToConversation(conversationResource.id, {
type: "message",
from: { id: "xxxxxxx" },
recipient: { id: sUserId },
text: 'This a message from Bot Connector Client (NodeJS)'
});
appId & appPassword are valid (from .env file), if they are wrong I can not receive messages from TEAMS client
I have the same code to create a conversation in a .NET bot and it works for me:
var parameters = new ConversationParameters
{
Members = new[] { new ChannelAccount(sUserId) },
ChannelData = new TeamsChannelData
{
Tenant = new TenantInfo(sTenantId),
},
};
retValue = await connectorClient.Conversations.CreateConversationAsync(parameters);
What is wrong in my node.js code?
Thanks,
Diego
Have you trusted the service? It don't think so based on your code, and it's a classic cause of 401 in your case.
In node.js, do the following:
MicrosoftAppCredentials.trustServiceUrl(serviceUrl);
If you want more details around that, have a look to the documentation about getting 401 when sending proactive messages here
And also this SO answer about Teams and Proactive messaging, in particular last block.
Proactive messaging bot in Teams without mentioning the bot beforehand
I'm trying to get my FCM web notifications to contain a clickable link to my site, using the firebase admin SDK (version 7.0.0) for node.js. As far as I can tell I'm following the documentation to a T, but I'm unable to get the link working. To clarify, my notifications are working fine otherwise, it's just the link that I haven't got to work.
The documentation states:
For notification messages sent from the app server, the FCM JavaScript API supports the fcm_options.link key. Typically this is set to a page in your web app
I've included webpush.fcm_options.link inside my notification message. I've made sure to include an explicit notification payload in my message, as the documentation states that data messages don't support fcm_options.link.
Here's the structure of my message currently:
{
notification: {
title: 'Title',
body: 'Body',
},
data: {
// my data here
},
webpush: {
notification: {
requireInteraction: true,
icon: '/icons/notification.png'
},
fcm_options: {
link: 'https://example.com/'
}
},
// android: {},
// apns: {},
topic: 'sometopic'
};
Here's the function I'm using to send the message:
const admin = require('firebase-admin')
const sendMessage = message => {
admin
.messaging()
.send(message)
.then(response => {
console.log(response)
})
.catch(error => {
console.log(error)
});
};
The link property should be working according to the documentation: my url includes https and my notification is being sent from the app server, and includes an explicit notification payload. At the moment, clicking on the notification just makes it disappear, with nothing else happening.
UPDATE: I worked out what the issue was - my service worker was using the importScripts function, but I was using an out-of-date version of the firebase script that didn't support fcm_options.link. I changed it to my current version of firebase (5.8.5) and it works. All sorted!
in notification try This
"notification":{
"title":"IssA",
"body":"Lafi",
"icon": "Icon URL",
"click_action": "Your URL here"
}
In the last version, using firebase admin in node js, this is the right configuration:
var message = {
notification: {
title: "",
body: ""
},
webpush: {
fcmOptions: {
link: "https://yourlink.web.app"
}
}
};
i'm implementing razorpay payment gateway in my React.js app with backend nodejs.
here frontend.jsx
razorpayHandler = () =>{
const payment_amount = this.props.TotalPrice;
const backend_url = 'https://25234399bb.ngrok.io';
const self = this;
const options = {
key: config.RAZOR_PAY_KEY,
amount: payment_amount * 100,
name: 'StanPlus',
description: 'pay your ambulance fare',
handler(response) {
const paymentId = response.razorpay_payment_id;
const url = backend_url+'/razorpay/'+paymentId+'/'+payment_amount+'/'+self.id;
console.log(paymentId)
// Using my server endpoints to capture the payment
fetch(url, {
method: 'get',
headers: {
"Content-type": "application/x-www-form-urlencoded; charset=UTF-8"
}
})
.then(resp => resp.json())
.then(function (data) {
console.log(data)
})
.catch(function (error) {
console.log('Request failed', error);
});
},
theme: {
color: '#40A9FF',
},
};
const rzp1 = new window.Razorpay(options);
rzp1.open();
}
backend.js(nodejs)
var express = require('express');
var router = express.Router();
var config = require('../config');
const Razorpay = require('razorpay');
const instance = new Razorpay({
key_id: config.razorpay_live_key,
key_secret: config.razorpay_live_secret,
});
router.get('/:payment_id/:amount/:BID',function(req,res,next){
const {payment_id } = req.params;
const {BID} = req.params;
const amount = Number(req.params.amount*100);
instance.payments.capture(payment_id, amount).then((data) => {
data.Bid = BID;
res.json(data);
}).catch((error) => {
res.json(error);
});
})
module.exports = router;
it showing me error
"statusCode":400,"error":{"code":"BAD_REQUEST_ERROR","description":"The id provided does not exist"
but if the same code if do process using test key its getting successfully completed but it is not working with live api.
here i'm passing an extra parameter to the backend which required for us but if removed that parameter then also it is not working.but with parameter it is working with test api.
when we send request to backend it is generating id and sending to backend also but still it showing The id provided does not exist.
if you are using test mode then just remove order_id parameter from json object.
I also faced this error a week ago. This error arrived when we changed the test keys to the production keys for final payment to work.
So I faced this issue The id provided does not exist because of the mismatch of Razorpay Keys on the frontend and backend side(node.js side.)
So make sure you have the same client key and secret of the production environment on both backend and frontend side.
Let me know in comments if it still is not resolved.
For Test Remove the OrderId from your options json data.
For Live mode Pass the autogenerated Orderid From the user Control.
Removing order_id is not good practice we should follow documentation.
To get order_id in React you have to first create a order in your backend eg(node.js). follow this steps to get order_id from Razorpay.
Step - 1
var instance = new Razorpay({ key_id: 'YOUR_KEY_ID', key_secret: 'YOUR_KEY_SECRET'})
this will initiate new Razorpay object.
Step - 2
MyOrder = instance.orders.create({amount, currency, receipt, notes})
this will create an order for you and then you have access to order_id. You can log MyOrder to see more available attributes or just console.log(MyOrder.id) to get order_id
and finally you have to pass your order_id in your case you have to pass order_id in options.
Note : You can access order id like this MyOrder.id
for more information check official doc.
you can find Razorpay SDKs for various Platform here
If you are using for payments, than remove order_id from options JSON value.
var options = {
"key": "xxxxxxxxxxxxxxx", // Enter the Key ID generated from the Dashboard
"amount": "50000", // Amount is in currency subunits. Default currency is INR. Hence, 50000 refers to 50000 paise
"currency": "INR",
"name": "Acme Corp",
"description": "Test Transaction",
"image": "https://example.com/your_logo",
// "order_id": "order_9A33XWu170gUtm", //This is a sample Order ID. Pass the `id` obtained in the response of Step 1
"handler": function (response){
alert(response.razorpay_payment_id);
alert(response.razorpay_order_id);
alert(response.razorpay_signature)
},
"prefill": {
"name": "Gaurav Kumar",
"email": "gaurav.kumar#example.com",
"contact": "9999999999"
},
"notes": {
"address": "Razorpay Corporate Office"
},
"theme": {
"color": "#3399cc"
}
};
This error happens when you pass an incorrect order_id to trigger the payment modal. Basically an order_id that does not belong to your razorpay account, or an invalid one.
Example: if you generated an order_id with one set of credentials and use another set of credentials afterwards, this issue can happen.
I too faced the same problem while integrating Razorpay for subscription payments
Initially, I passed order_id in the options param, which yielded the error -
{
"code": "BAD_REQUEST_ERROR",
"description": "The id provided does not exist",
"source": "business",
"step": "payment_initiation",
"reason": "input_validation_failed",
"metadata": {}
}
Hence replaced order_id with subscription_id.
Works now!
Check for the rp_type,
for subscription pass options["subscription_id"],
for orders pass options["order_id"]
I am newbie to push notifications, and i have done the code part which i have taken reference from googling and it is working fine, but my query is :
sending push notification to group of people (using array)
and there is chance to be at least one wrong gcm-id in that array
if there is a wrong gcm-id, populates error like "Not Registered" or "MisplacingId" (while sending individually)
Now, the gcm-id is in an array, then the push will send for remaining people or it will block there itself?
and here is my code :
var GCM = require('gcm').GCM;
var apiKey = 'xyz';
var gcm = new GCM('apiKey');
var message = {
registration_id: ['x','y'],
collapse_key: 'Hello',
priority: 'high',
contentAvailable: true,
delayWhileIdle: true,
timeToLive: 3,
};
gcm.send(message, function(err, messageId){
if (err) {
console.log("Something has gone wrong!");
console.log(err);
} else {
console.log("Sent with message ID: ", messageId);
}
});
and please tell me there is any limt(Number of gcmid's)? in one push?
It will send push notifications to all the registration ids even if few of them appear to be invalid in between the array.
Sample response when the registration id is not valid
{
multicast_id: 8976424350191695000,
success: 1,
failure: 1,
canonical_ids: 1,
results: [
{
registration_id: "value-of-correct-registration-id",
message_id: "0:1460568231005603%ade1213ff9fd7ecd"
},
{
error: "InvalidRegistration"
}
]
}
The success and failure count will show the number of push notifications sent and failed. And there is no limit applied on the number of registration ids.
I am trying to use Firebase, Node.js, and Google Cloud Messaging to send push notifications for an iOS app. Below is the Node.js code
var Firebase = require('firebase'),
gcm = require('node-gcm')
;
var pushRef = new Firebase("https://<myapp>.firebaseio.com/ios/queue/tasks");
pushRef.on("child_added", function(snapshot) {
console.log("child added event registers");
var notificationData = snapshot.val();
sendNotification(notificationData);
snapshot.ref().remove();
});
function sendNotification(notificationData) {
var message = new gcm.Message({
notification: {
title: "Title",
body: notificationData.message
}
});
var sender = new gcm.Sender(<my Google Server Key>);
var registrationTokens = [notificationData.recipientId];
console.log("about to send message");
console.log("this is the registration token: " + registrationTokens);
sender.send(message, { registrationTokens: registrationTokens }, 10, function (err, response) {
if(err) {
console.error(err);
} else {
console.log(response);
}
});
}
There are no errors, and all of the console.log statements register. However, I never receive a push notification on my device. Here is the console.log(response):
{ multicast_id: 7398179070839209000,
success: 1,
failure: 0,
canonical_ids: 0,
results: [ { message_id: '0:1457564370785913%939a5f18939a5f18' } ] }
What might be going on? It looks like things should be working, but they aren't
By default messages are sent with standard priority, which according to Google Cloud Messaging docs:
This is the default priority for message delivery. Normal priority messages won't open network connections on a sleeping device, and their delivery may be delayed to conserve battery. For less time-sensitive messages, such as notifications of new email or other data to sync, choose normal delivery priority.
Somehow this normal priority seems to affect iOS more than Android apps.
To get the messages delivered immediately, you'll want to add priority: 'high' to you message:
var message = new gcm.Message({
priority : "high",
notification: {
title: "Title",
body: notificationData.message
}
});