I managed to use the createChatInviteLink function but I don't know how to extract the invitation link to send to the user.
function create_chat_link(chat_id){
chat_id = ‘chat_id';
max_usos = 1;
var url = telegramUrl + '/createChatInviteLink?chat_id=' + chat_id + '&member_limit=' + max_usos;
return UrlFetchApp.fetch(url);
}
How can I extract the link that is generated when using that method?
When using Telegram Bot API you will receive a json formatted response upon calling your url.
In your case for createChatInviteLink method this response will look something like this:
{
"ok": true,
"result": {
"invite_link": "https://t.me/+fLsUa7gOGDxjOOA2",
"creator": {
"id": 210111457,
"is_bot": true,
"first_name": "...",
"username": "..."
},
"creates_join_request": false,
"is_primary": false,
"is_revoked": false
}
}
Check invite_link field to find your invitation link.
Related
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"
}
I am using a PayPal payout API to transfer money, its working perfect in sandbox environment but when I changed it to live environment it is throwing some error:
text: '{"name":"VALIDATION_ERROR","message":"Invalid request - see details","debug_id":"a641429b40e07","information_link":"https://developer.paypal.com/docs/api/payments.payouts-batch/#errors","details":[{"field":"items[0].receiver","location":"body","issue":"may not be null"}],"links":[]}'
This is the code I am using to request a payout
let requestBody = {
"sender_batch_header": {
"recipient_type": "EMAIL",
"email_message": "SDK payouts test txn",
"note": "Enjoy your Payout!!",
"sender_batch_id": 'asd12432',
"email_subject": "This is a test transaction from SDK"
},
"items": [{
"note": "Your 5$ Payout!",
"amount": {
"currency": "USD",
"value": 20
},
"receiver": 'payment#reciever.com',
"sender_item_id": "Test_txn_1"
}]
}
// Construct a request object and set desired parameters
// Here, PayoutsPostRequest() creates a POST request to /v1/payments/payouts
let request = new paypal.payouts.PayoutsPostRequest();
request.requestBody(requestBody);
// Call API with your client and get a response for your call
let createPayouts = async function () {
let response = await client.execute(request);
console.log(`Response: ${JSON.stringify(response.statusCode)}`);
// If caladfl returns body in response, you can get the deserialized version from the result attribute of the response.
console.log(`Payouts Create Response: ${JSON.stringify(response.result)}`);
//res.redirect('/adam?payment=success');
res.redirect('/adam?payment=success');
}
createPayouts();
Im trying to create a classroom using googles classroom API. Whenever run the classroom.create function I always receive the same error message. I'm using the JSON format from their docs but I just can't get it to work. I think I must be missing something.
This is the function:
async function listCourses(auth) {
const classroom = google.classroom({ version: 'v1', auth });
//Read data from JSON
let data = fs.readFileSync("class.json");
let course = JSON.parse(data);
//Try and create course
try {
const res = await classroom.courses.create(course);
console.log(res.data);
}
catch (error) {
console.log(error)
}
//List all current courses
classroom.courses.list({
pageSize: 10,
}, (err, res) => {
if (err) return console.error('The API returned an error: ' + err);
const courses = res.data.courses;
if (courses && courses.length) {
console.log('Courses:');
courses.forEach((course) => {
console.log(`${course.name} (${course.id})`);
});
} else {
console.log('No courses found.');
}
});
}
This is the JSON:
{
"id": "157942918368",
"name": "English - 9Y",
"section": "Period 2",
"ownerId": "me",
"courseState": "ACTIVE"
}
This is the error message:
code: 400,
errors: [
{
message: `Invalid JSON payload received. Unknown name "name": Cannot bind query parameter. Field 'name' could not be found in request message.\n` +
`Invalid JSON payload received. Unknown name "ownerId": Cannot bind query parameter. Field 'ownerId' could not be found in request message.\n` +
`Invalid JSON payload received. Unknown name "courseState": Cannot bind query parameter. Field 'courseState' could not be found in request message.\n` +
`Invalid JSON payload received. Unknown name "id": Cannot bind query parameter. Field 'id' could not be found in request message.\n` +
`Invalid JSON payload received. Unknown name "section": Cannot bind query parameter. Field 'section' could not be found in request message.`,
reason: 'invalid'
}
]
I believe your goal as follows.
You want to create new course using googleapis for Node.js.
Modification points:
At googleapis for Node.js, please put the request body to resource and/or requestBody.
I think that the reason of your error message is due to this.
When "id": "157942918368", is used, an error of Request contains an invalid argument. occurs.
When "courseState": "ACTIVE" is used, an error of "#CourseStateDenied This user cannot create or transition courses into the requested state." occurs.
"PROVISIONED" can be used in this case.
When above points are reflected to your script, it becomes as follows.
Modified script:
From:
const res = await classroom.courses.create(course);
To:
const res = await classroom.courses.create({ requestBody: course });
or
const res = await classroom.courses.create({ resource: course });
And also, please modify your request body as follows.
From:
{
"id": "157942918368",
"name": "English - 9Y",
"section": "Period 2",
"ownerId": "me",
"courseState": "ACTIVE"
}
To:
{
"name": "English - 9Y",
"section": "Period 2",
"ownerId": "me",
}
Note:
In this modification, it supposes that your const classroom = google.classroom({ version: 'v1', auth }); can be used for using the method of courses.create in Classroom API.
References:
Method: courses.create
googleapis for Node.js
I'm using Express Validator for validate user req. I'm trying to create custom response like this:
{
"code": 300,
"status": false,
"message": "Your email is not valid",
"param": "email",
"value": "kevin"
}
but what I got is
[
{
"code": 300,
"status": false,
"message": "Your email is not valid",
"param": "email",
"value": "kevin"
}
]
Here is my code:
controller.js:
const errors = validationResult(req).formatWith(utils.error);
if(!errors.isEmpty()){
res.status(300).json(errors.array());
}
ResUtils.js
error({msg, param, value, nestedErrors}) {
var code = 300;
var format = {code, status:false, message:msg, param:param, value:value, nestedErrors:nestedErrors};
return format;
}
How do I can get the response as Json, without [].
Thankyou.
Well, this state is good in my opinion, there is possibility of multiple errors so you should process all messages in a frontend app (or mobile or whatever) to give user informations about all invalid fields (or options or whatever). If you really need only a object, you can pick a first error message from an array for example.
if(!errors.isEmpty()){
const errorsArray = errors.array();
res.status(300).json(errorsArray[0]);
}
But as I said it is better approach to handle all error messages.
I have this function below which allows me to send a mail with mandrill nodeJS API :
var mandrill = require('mandrill-api/mandrill');
var mandrill_client = new mandrill.Mandrill(config.values.mandrill_api_key);
exports.sendMail = function(htmlContent, textContent, subject, from_email, from_name, to_email, to_name ,reply_to_email, callback) {
var message = {
"html": htmlContent,
"text": textContent,
"subject": subject,
"from_email": from_email,
"from_name": from_name,
"to": [{
"email": to_email,
"name": to_name,
"type": "to"
}],
"headers": {
"Reply-To": reply_to_email
},
"important": false
};
var async = false;
mandrill_client.messages.send({"message": message, "async": async}, function(result) {
console.log(result);
callback(result);
}, function(e) {
console.log('A mandrill error occurred: ' + e.name + ' - ' + e.message);
});
};
On the mandrill console (https://mandrillapp.com/activity) I can see that emails have been successfully sent (status: Delivered).
But I don't get it in my gmail box nor hotmail box.
How to resolve this problem ?
Thanks,
Be sure, you're not using a testing API Key.
You can use a test key to experiment with Mandrill's API. No mail is actually sent, but webhooks trigger normally and you can generate synthetic bounces and complaints without impacting your reputation.
The problem is solved.
I had to add special fields into my DNS zone : DKIM and SPF
http://help.mandrill.com/entries/22030056-how-do-i-add-dns-records-for-my-sending-domains