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!");
});
Related
I have to use the data I receive, in particular I have to be able to use the data in 'properties':
I don't understand how to call them, instead of console.log
I tried to use an Object.values(), but so I can't access the 'properties' data that I have to reuse later.
const response = await notion.databases.query({
database_id: databaseId,
page_size: 2
});
var effort_data = []
effort_data.push({
response
})
effort_data.map(data => {
Object.values(data.response.results).map((data) => {
console.log('data', data)
})
})
this is my response :
data {
object: 'page',
id: '3b8e203e-79ae-4ddc-ba3a-e0f5b30f4d4e',
created_time: '2023-01-25T13:51:00.000Z',
last_edited_time: '2023-01-25T13:59:00.000Z',
created_by: { object: 'user', id: '204c1b2e-0c59-4605-be45-de1fc9916416' },
last_edited_by: { object: 'user', id: '204c1b2e-0c59-4605-be45-de1fc9916416' },
cover: null,
icon: { type: 'emoji', emoji: '👽' },
parent: {
type: 'database_id',
database_id: '1b02ff59-8cdb-47fb-a6f9-5904bcecbe72'
},
archived: false,
properties: {
Assignees: { id: '%24v1Q', type: 'people', people: [] },
Type: { id: '9dB%5E', type: 'select', select: [Object] },
Progetti: {
id: '%3AirU',
type: 'relation',
relation: [Array],
has_more: false
},
Epics: { id: 'B%7BSE', type: 'relation', relation: [], has_more: false },
'Creato da': { id: 'D%5Dzr', type: 'created_by', created_by: [Object] },
'Flussi coinvolti': { id: 'EFdR', type: 'relation', relation: [], has_more: false },
'Sprint corrente?': { id: 'G%5Cvg', type: 'formula', formula: [Object] },
Sprint: { id: 'Jz.%40', type: 'multi_select', multi_select: [] },
'🏃 Sprint': { id: 'O%3DHc', type: 'relation', relation: [], has_more: false },
Settore: { id: 'XYh%5D', type: 'select', select: null },
Timeline: { id: '_G%2Bl', type: 'date', date: [Object] },
Tasks: {
id: 'bXv%3F',
type: 'relation',
relation: [Array],
has_more: false
},
'Data creazione': {
id: 'e_r%7D',
type: 'created_time',
created_time: '2023-01-25T13:51:00.000Z'
},
'Epic status': { id: 'nRGT', type: 'rollup', rollup: [Object] },
'Ultimo aggiornamento da': { id: 'ogbh', type: 'last_edited_by', last_edited_by: [Object] },
'Data ultimo aggiornamento': {
id: 'p%5CYK',
type: 'last_edited_time',
last_edited_time: '2023-01-25T13:59:00.000Z'
},
Priority: { id: '%7BMEq', type: 'select', select: [Object] },
Status: { id: '%7CF4-', type: 'select', select: [Object] },
Name: { id: 'title', type: 'title', title: [Array] }
},
url: 'https://www.notion.so/Endpoint-per-ordini-card-da-esterni-3b8e203e79ae4ddcba3ae0f5b30f4d4e'
}
I am following this toutorial: https://github.com/codeBelt/open-api-documentation/blob/master/src/openApiDocumentation.js
Can I validate my openApiDocumentation.js file somewhow? I get:
Unable to render this definition
The provided definition does not specify a valid version field.
Please indicate a valid Swagger or OpenAPI version field. Supported version fields are swagger: "2.0" and those that match openapi: 3.0.n (for example, openapi: 3.0.0).
I am attaching mi .js file. Maybe you guys will see a typo here. Thanks in advance.
.js file:
const USER_TYPES = {
EXCHANGE: 'xxx',
GIVEAWAY: 'xxx'
}
const openApiDocumentation = {
openapi: '3.0.1',
info: {
version: '1.3.0',
title: 'xxx',
description: 'xxx',
contact: {
name: 'xxx',
email: 'xxx',
}
},
license: {
name: 'Apache 2.0',
url: 'https://www.apache.org/licenses/LICENSE-2.0.html',
},
servers: [
{
url: 'http://localhost:4000/',
description: 'Local server',
},
],
tags: [
{
name: 'Books CRUD operations',
},
],
paths: {
'/findAllBooks': {
get: {
tags: ['CRUD operations'],
description: 'Get all Book offers',
operationId: 'getUsers',
parameters: [
{
name: 'page',
in: 'query',
schema: {
type: 'integer',
default: 1,
},
required: true,
description: 'Page numer used pagination.',
},
],
responses: {
'200': {
description: 'Books were obtained',
content: {
'application/json': {
schema: {
$ref: '#/components/schemas/Books',
},
},
},
},
'500': {
description: 'Missing parameters',
content: {
'application/json': {
schema: {
$ref: '#/components/schemas/Error',
},
example: {
message: 'page qyery parameter is missing',
internal_code: 'missing_parameters',
},
},
},
},
},
},
},
},
components: {
schemas: {
coverImg: {
type: 'string',
example: 'http:',
},
image: {
type: 'string',
example: 'http',
},
category: {
type: 'string',
example: 'Crafts & Hobbies',
},
linkTypes: {
type: 'object',
properties: {
coverImg: {
$ref: '#/components/schemas/coverImg',
},
images: {
type: 'array',
items: {
$ref: '#/components/schemas/image',
},
}
}
},
offerID: {
type: 'string',
example: '27301927',
},
userID: {
type: 'string',
example: 'efdc5192',
},
title: {
type: 'string',
example: 'Quilting For Dummies',
},
description: {
type: 'string',
example: 'You ',
},
categories: {
type: 'array',
items: {
$ref: '#/components/schemas/category',
},
},
links: {
type: 'object',
items: {
$ref: '#/components/schemas/linkTypes',
},
},
offerType: {
type: 'string',
enum: USER_TYPES,
default: USER_TYPES.EXCHANGE,
},
Book: {
type: 'object',
properties: {
offerID: {
$ref: '#/components/schemas/offerID',
},
userID: {
$ref: '#/components/schemas/userID',
},
title: {
$ref: '#/components/schemas/title',
},
description: {
$ref: '#/components/schemas/description',
},
categories: {
$ref: '#/components/schemas/categories',
},
imageLinks: {
$ref: '#/components/schemas/links',
},
offerType: {
$ref: '#/components/schemas/offerType',
},
},
},
Books: {
type: 'object',
properties: {
users: {
type: 'array',
items: {
$ref: '#/components/schemas/Book',
},
},
},
},
Error: {
type: 'object',
properties: {
message: {
type: 'string',
},
internal_code: {
type: 'string',
},
},
},
},
},
};
There are few mistakes,
license must be inside the info object
info: {
version: '1.3.0',
title: 'xxx',
description: 'xxx',
contact: {
name: 'xxx',
email: 'xxx' // make sure you have used valid email address!
},
license: {
name: 'Apache 2.0',
url: 'https://www.apache.org/licenses/LICENSE-2.0.html'
}
}
enum will allow only array not an object and here you have passed object USER_TYPES, corrected below:
const USER_TYPES = {
EXCHANGE: 'xxx',
GIVEAWAY: 'xxx'
};
const USER_TYPES_ENUM = [
USER_TYPES.EXCHANGE,
USER_TYPES.GIVEAWAY
];
offerType: {
type: 'string',
enum: USER_TYPES_ENUM,
default: USER_TYPES.EXCHANGE,
},
For best practice use https://editor.swagger.io/ (also they have provided a option to convert json to yaml under Edit > Convert to YAML)!
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);
});
})
I am trying to populate a fields that is nested inside my model but it is not populating.
This is a field inside my model.
pendingChanges: {
credentials: {
university: {
name: { type: String },
major: { type: String },
majorGpa: { type: Number },
},
school: {
name: { type: String },
degreeType: { type: String },
degree: { type: String },
},
subjects: [{ type: mongoose.Schema.Types.ObjectId, ref: 'subject' }],
workExperience: {
type: { type: String },
from: { type: Date },
to: { type: Date },
},
},
},
I am trying to populate subjects key nested inside.
This is what I have done so far.
const teacher = (await this.findById(id))
.populate({
path: 'pendingChanges',
populate: {
path: 'credentials',
populate: {
path: 'subjects',
},
},
});
I found the solution. Here's what I did to make it work.
const data = await this.findOne(query)
.populate({
path: 'pendingChanges.credentials.subjects',
});
Whenever I try to add a variable to my dialog title, dialog.open does not work and no errors are thrown.
If I remove the variable from the title everything works fine, it is only when I add the variable to the title
I execute this before I define dialog
app.post('/create', function(req, res) {
var users = []
var {
text, trigger_id
} = req.body;
text = text.toUpperCase()
var issuetypes = []
axios({
method: 'get',
url: baseURL + 'project/' + text
}).then(function(response) {
for (var i = 0; i < response.data.issueTypes.length; i++) {
issuetypes.push({
label: response.data.issueTypes[i].name,
value: response.data.issueTypes[i].name
});
}
Does not work:
const dialog = {
token: botToken,
trigger_id,
dialog: JSON.stringify({
title: 'Create a new ' + text + ' Ticket',
callback_id: 'submit-ticket',
submit_label: 'Submit',
elements: [{
label: 'Project',
type: 'text',
name: 'project'
}, {
label: 'Summary',
type: 'text',
name: 'summary',
}, {
label: 'Description',
type: 'textarea',
name: 'description',
optional: true,
}, {
label: 'Type',
type: 'select',
name: 'type',
options: issuetypes,
}, {
label: 'Reporter',
type: 'select',
name: 'reporter',
optional: true,
options: [{
label: 'Reporter',
value: 'reporter'
}, ],
}, {
label: 'Link',
type: 'select',
name: 'epic',
optional: true,
options: [{
label: 'Epic',
value: 'epic'
}, ],
}, ],
}),
};
Works:
const dialog = {
token: botToken,
trigger_id,
dialog: JSON.stringify({
title: 'Create a new Ticket',
callback_id: 'submit-ticket',
submit_label: 'Submit',
elements: [{
label: 'Project',
type: 'text',
name: 'project'
}, {
label: 'Summary',
type: 'text',
name: 'summary',
}, {
label: 'Description',
type: 'textarea',
name: 'description',
optional: true,
}, {
label: 'Type',
type: 'select',
name: 'type',
options: issuetypes,
}, {
label: 'Reporter',
type: 'select',
name: 'reporter',
optional: true,
options: [{
label: 'Reporter',
value: 'reporter'
}, ],
}, {
label: 'Link',
type: 'select',
name: 'epic',
optional: true,
options: [{
label: 'Epic',
value: 'epic'
}, ],
}, ],
}),
};
Then I call dialog.open
axios.post("https://slack.com/api/dialog.open", qs.stringify(dialog))
.then(
(result) => {
res.send('');
}).catch(function(err) {
console.error(err);
})
}).catch(function(err) {
console.error(err);
})
});
Any ideas as to why dialog.open does not work?
The reason the Dialog is not shown when you have the variable in the title is that you exceed the maximum length of 24 chars for a title. (see here for reference)
You should however received the validation error from the API though as documented for the dialog.open method:
"The field `title` cannot be longer than 24 characters"
There must be another reason why you are not receiving it.