firebase callable node function - node.js

I try to use a node function in firebase callable function and wehn I try to use it as described I see this warning on VS code. any help? on what I can do
module "c:/Users/firat/Desktop/vuedg3/functions/node_modules/iyzipay/lib/Iyzipay"
Could not find a declaration file for module 'iyzipay'. 'c:/Users/firat/Desktop/vuedg3/functions/node_modules/iyzipay/lib/Iyzipay.js' implicitly has an 'any' type.
Try npm install #types/iyzipay if it exists or add a new declaration (.d.ts) file containing declare module 'iyzipay';ts(7016)
and this callable function return null when I try and call it from web app
this is my entire code
exports.trypay = functions.https.onCall((data, context) => {
var Iyzipay = require('iyzipay');
var iyzipay = new Iyzipay({
apiKey: "sandbox-11",
secretKey: "sandbox-11",
uri: 'https://sandbox-api.iyzipay.com'
});
var request = {
locale: Iyzipay.LOCALE.TR,
conversationId: '123456789',
price: '1',
paidPrice: '1.2',
currency: Iyzipay.CURRENCY.TRY,
installment: '1',
basketId: 'B67832',
paymentChannel: Iyzipay.PAYMENT_CHANNEL.WEB,
paymentGroup: Iyzipay.PAYMENT_GROUP.LISTING,
paymentCard: {
cardHolderName: 'John Doe',
cardNumber: '5528790000000008',
expireMonth: '12',
expireYear: '2030',
cvc: '123',
registerCard: '0'
},
buyer: {
id: 'BY789',
name: 'John',
surname: 'Doe',
gsmNumber: '+905350000000',
email: 'email#email.com',
identityNumber: '74300864791',
lastLoginDate: '2015-10-05 12:43:35',
registrationDate: '2013-04-21 15:12:09',
registrationAddress: 'Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1',
ip: '85.34.78.112',
city: 'Istanbul',
country: 'Turkey',
zipCode: '34732'
},
shippingAddress: {
contactName: 'Jane Doe',
city: 'Istanbul',
country: 'Turkey',
address: 'Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1',
zipCode: '34742'
},
billingAddress: {
contactName: 'Jane Doe',
city: 'Istanbul',
country: 'Turkey',
address: 'Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1',
zipCode: '34742'
},
basketItems: [
{
id: 'BI101',
name: 'Binocular',
category1: 'Collectibles',
category2: 'Accessories',
itemType: Iyzipay.BASKET_ITEM_TYPE.PHYSICAL,
price: '0.3'
},
{
id: 'BI102',
name: 'Game code',
category1: 'Game',
category2: 'Online Game Items',
itemType: Iyzipay.BASKET_ITEM_TYPE.VIRTUAL,
price: '0.5'
},
{
id: 'BI103',
name: 'Usb',
category1: 'Electronics',
category2: 'Usb / Cable',
itemType: Iyzipay.BASKET_ITEM_TYPE.PHYSICAL,
price: '0.2'
}
]
};
iyzipay.payment.create(request, function (err, result) {
return('result:'+result + 'error:'+err);
});
})

Related

Mongoose Aggregate - Group by field from array

For one of my project, I am working on MongoDB database and Mongoose as ODM in nestjs project.
One of my collection is looks like this data:
[
{
_id: '56cb91bdc3464f14678934ca',
organization: 'New Circle Ltd',
rooms: [
{
name: 'Alex',
workId: 'abc',
},
{
name: 'John',
workId: 'cde',
},
{
name: 'John',
workId: 'abc',
},
{
name: 'Alex',
workId: 'cdlw',
},
{
name: 'Alex',
workId: 'rps',
},
],
},
];
The requirement is to get one data by id and the data should be like the data provided bellow.
{
_id: '56cb91bdc3464f14678934ca',
organization: 'New Circle Ltd',
rooms: [
{
name: 'Alex',
workIds: ['abc', 'cdlw', 'rps'],
},
{
name: 'John',
workIds: ['cde', 'abc'],
},
],
},
Please suggest me how can I get this data

how can I add nestead array of objects using convert-excel-to-json

I am trying to insert data from excel sheet using convert-excel-to-json npm. I am able to basic format of my data but i want to add also images as a nested array.
Here Is my code:
app.post("/upload-excel", async (req, res) => {
const newpath = __dirname + "/files/";
const file = req.files.file;
const filename = file.name;
const worksheetsArray = xlsx.parse(filename); // parses a file
const excelData = excelToJson({
sourceFile: filename,
sheets: [{
// Excel Sheet Name
name: worksheetsArray[0].name,
// Header Row -> be skipped and will not be present at our result object.
header: {
rows: 1
},
// Mapping columns to keys
columnToKey: {
A: '_id',
B: 'name',
C: 'address',
D: 'age',
}
}]
});
console.log(excelData);
});
The above code output is:
{
Customers: [
{ _id: 1, name: 'Jack Smith', address: 'Massachusetts', age: 23 },
{ _id: 2, name: 'Adam Johnson', address: 'New York', age: 27 },
{
_id: 3,
name: 'Katherin Carter',
address: 'Washington DC',
age: 26
},
{ _id: 4, name: 'Jack London', address: 'Nevada', age: 33 },
{ _id: 5, name: 'Jason Bourne', address: 'California', age: 36 }
]
}
The expected output is: Here i have added extra images
{
Customers: [
{ _id: 1, name: 'Jack Smith',images:[{id:1, src:"sadasd.com"}], address: 'Massachusetts', age: 23 },
{ _id: 2, name: 'Adam Johnson', address: 'New York',images:[{id:1, src:"sadasd.com"}] age: 27 },
{
_id: 3,
name: 'Katherin Carter',
address: 'Washington DC',
age: 26,
images:[{id:1, src:"sadasd.com"}, {id:1, src:"sadasd.com"}],
{ _id: 4, name: 'Jack London', address: 'Nevada',images:[{id:1, src:"sadasd.com"}], {id:1, src:"sadasd.com"}], age: 33 },
{ _id: 5, name: 'Jason Bourne',images:[{id:1, src:"sadasd.com"}, address: 'California', age: 36 }
]
}

Accessing JSON objects in this format

const login = await Signupdetails.find(req.body);
login =
[
{
PersonalInformation: {
firstName: 'aravind',
lastName: 'john',
phoneNumber: 9736363777,
DOB: 1999-07-08T18:30:00.000Z
},
Address: {
street: 'pillai',
city: 'Chennai',
pincode: 89997,
state: 'kerala',
country: 'India'
},
password: 'social',
_id: 607804f65c166c32144ae227,
email: 'hari#gmail.com',
userName: 'hari',
__v: 0
}
]
If I try using login.userName ,its showing undefined . This is a part of my Get API request . I used node.js and mongodb
You have a list, if you want login to be an Object, remove '[' characters:
login =
{
PersonalInformation: {
firstName: 'aravind',
lastName: 'john',
phoneNumber: 9736363777,
DOB: 1999-07-08T18:30:00.000Z
},
Address: {
street: 'pillai',
city: 'Chennai',
pincode: 89997,
state: 'kerala',
country: 'India'
},
password: 'social',
_id: 607804f65c166c32144ae227,
email: 'hari#gmail.com',
userName: 'hari',
__v: 0
}
On the other hand, if you want login to be a list, you have to access:
login[0].userName

How to intercept bot messages in SDK4

I have an SDK 4 bot, logging user interactions to Blob storage. I would also like to log bot responses also. In SDK 3 I did this with something like ...
bot.use({
// Code for handling message receives
receive: function (session, event, next) {
var userId = session.address.user.id;
logger.logUserConversation(session.text, userId, session.address.conversation.id, userId);
next();
},
// Code for handling message sends
send: function (event, next) {
var text = event.text;
if(!event.text) {
text = "Attachments sent";
}
logger.logUserConversation(text, 'bot', event.address.conversation.id, event.address.user.id);
next();
}
});
In SDK 4, I am able to configure middleware which intercepts user activity, but I cannot seem to intercept bot activity. I can't seem to find anything in the documentation, but I am new to SDK 4 and might be missing something.
Anybody know how I can intercept both user and bot events, so that I can log?
There are already 2 samples in Node.js in the official samples repository:
1 called "Logger": https://github.com/Microsoft/BotBuilder-Samples/tree/master/samples/javascript_nodejs/25.logger
1 called "transcript Logger": https://github.com/Microsoft/BotBuilder-Samples/tree/master/samples/javascript_nodejs/26.transcript-logger
I gave a try to the 1st one and can confirm that it logs both user input and bot replies. It is logging every activity, even ConversationUpdate.
See example of transcript generated below:
Activity Received: { type: 'conversationUpdate',
membersAdded: [ { id: '1', name: 'Bot' } ],
channelId: 'emulator',
conversation: { id: '36e25420-ec19-11e8-8040-2ba105e71021|livechat' },
id: '370f7ea0-ec19-11e8-9ee4-fb60855d29c5',
localTimestamp: 2018-11-19T16:36:07.000Z,
recipient: { id: '1', name: 'Bot', role: 'bot' },
timestamp: 2018-11-19T16:36:07.689Z,
from:
{ id: 'fd3fd64d-6297-4e36-98c5-ee398857f2b6',
name: 'User',
role: 'user' },
locale: '',
serviceUrl: 'http://localhost:58083' }
Activity Received: { type: 'conversationUpdate',
membersAdded:
[ { id: 'fd3fd64d-6297-4e36-98c5-ee398857f2b6', name: 'User' } ],
channelId: 'emulator',
conversation: { id: '36e25420-ec19-11e8-8040-2ba105e71021|livechat' },
id: '3711c890-ec19-11e8-9ee4-fb60855d29c5',
localTimestamp: 2018-11-19T16:36:07.000Z,
recipient: { id: '1', name: 'Bot', role: 'bot' },
timestamp: 2018-11-19T16:36:07.705Z,
from:
{ id: 'fd3fd64d-6297-4e36-98c5-ee398857f2b6',
name: 'User',
role: 'user' },
locale: '',
serviceUrl: 'http://localhost:58083' }
Activity Received: { text:
'I am a bot that demonstrates custom logging. We will have a short conversation where I ask a few questions to collect your name and age, then store those values in UserState for later use. after this you will be able to find a log of the conversation in the folder set by the transcriptsPath environment variable Say anything to continue.',
inputHint: 'acceptingInput',
channelId: 'emulator',
serviceUrl: 'http://localhost:58083',
conversation: { id: '36e25420-ec19-11e8-8040-2ba105e71021|livechat' },
from: { id: '1', name: 'Bot', role: 'bot' },
recipient:
{ id: 'fd3fd64d-6297-4e36-98c5-ee398857f2b6',
name: 'User',
role: 'user' },
replyToId: '3711c890-ec19-11e8-9ee4-fb60855d29c5',
type: 'message',
timestamp: 2018-11-19T16:36:08.408Z }
Activity Received: { type: 'message',
text: 'test',
from:
{ id: 'fd3fd64d-6297-4e36-98c5-ee398857f2b6',
name: 'User',
role: 'user' },
locale: '',
textFormat: 'plain',
timestamp: 2018-11-19T16:36:23.421Z,
channelData: { clientActivityId: '1542645367574.7109285295569892.0' },
entities:
[ { type: 'ClientCapabilities',
requiresBotState: true,
supportsTts: true,
supportsListening: true } ],
channelId: 'emulator',
conversation: { id: '36e25420-ec19-11e8-8040-2ba105e71021|livechat' },
id: '406fdad0-ec19-11e8-9ee4-fb60855d29c5',
localTimestamp: 2018-11-19T16:36:23.000Z,
recipient: { id: '1', name: 'Bot', role: 'bot' },
serviceUrl: 'http://localhost:58083' }
Activity Received: { text: 'What is your name, human?',
inputHint: 'expectingInput',
channelId: 'emulator',
serviceUrl: 'http://localhost:58083',
conversation: { id: '36e25420-ec19-11e8-8040-2ba105e71021|livechat' },
from: { id: '1', name: 'Bot', role: 'bot' },
recipient:
{ id: 'fd3fd64d-6297-4e36-98c5-ee398857f2b6',
name: 'User',
role: 'user' },
replyToId: '406fdad0-ec19-11e8-9ee4-fb60855d29c5',
type: 'message',
timestamp: 2018-11-19T16:36:23.443Z }
More details about the code that generated that is available on the project, here. If you look at it, the main point is:
if (activity.value === 'endOfInput') {
console.log(this.conversations[id]);
var transcriptfileName = util.format('%s/log_%s.transcript', process.env.transcriptsPath, id);
fs.writeFile(transcriptfileName, JSON.stringify(this.conversations[id], null, 3), function(err) {
if (err) throw err;
});
delete this.conversations[id];
}

How can I write vcard to a file

I tried to create a vcard via an API call. The following code shows,
var vcard = require('vcard-generator');
const vcardContent = vcard({
name: {
givenName: 'test',
middleName: '',
prefix: '',
suffix: '',
},
formattedNames: [{
text: '',
}],
nicknames: [{
text: '',
}],
works: [{
organization: 'AMT'
}],
emails: [{
type: 'work',
text: 'test#test.com',
}],
phones: [{
type: 'sms',
text: '+14035551515',
}, {
uri: 'sms://+14035551515',
}],
urls: [{
type: 'test1',
uri: 'https://test1.com',
}, {
type: 'test2',
uri: 'https://test2.com',
}],
});
console.log(vcardContent)
How can I write the above data as test.vcf file or any other npm available for handling vcard generation. And also I need to get the generated vcard via scaning QR code.
The Node.js fs package will allow you to write to the file system.
Writing to File System
var fs = require('fs');
var vcard = require('vcard-generator');
const vcardContent = vcard(
{
name: {
givenName: 'test',
middleName: '',
prefix: '',
suffix: '',
},
formattedNames: [{
text: '',
}],
nicknames: [{
text: '',
}],
works: [{
organization: 'AMT'
}],
emails: [{
type: 'work',
text: 'test#test.com',
}],
phones: [
{
type: 'sms',
text: '+14035551515',
},
{
uri: 'sms://+14035551515',
}
],
urls: [{
type: 'test1',
uri: 'https://test1.com',
}, {
type: 'test2',
uri: 'https://test2.com',
}],
});
fs.writeFile("/path/to/save/to", vardContent, function(err) {
if(err) {
return console.log(err);
}
console.log("Your vCard was saved!");
});

Resources