Добавление записи звонка при входящем.

const axios = require('axios');

module.exports = async (args) => {
	
	const contact_id = args.context.contact_id; 
	const contact_name = args.context.contact_name; 
	const contactResponsibleId = args.context.contact_responsible_id;
	const answered_user_id = parseInt(args.context.answered_user_id);

	const line_number = args.call_args.line_number;


    // пишем звонок
    const url = `https://${args.settings.domain}/api/v2/notes`;
    const headers = {
        'Content-Type': 'application/json',
        'Authorization': `Bearer ${args.crm_auth}`,
    };
    const data = {
        add: [{
            element_id: parseInt(contactId),
            element_type: 1, // 1 - Contact, 2 - Lead, 3 - Company
            note_type: 10, // 10 - Incoming call, 11 - Outgoing call
            params: {
                UNIQ: args.call_args.call_id,
                LINK: args.call_args.call_record_link,
                PHONE: `${args.call_args.src_num}  ` + 'На номер: ' + `${line_number} `,
                DURATION: parseInt(args.call_args.timestamp) - parseInt(args.call_args.call_answer_timestamp),
                SRC: 'sipuni',
                call_status: 4, //1 Left a voice message, 2 Call back later, 3 Not available, 4 The conversation took place, 5 Wrong number, 6 Did not get through, 7 Number is busy
                call_result: '',
            },
            created_by: answered_user_id,
            responsible_user_id: contactResponsibleId,
        }]
    };
    const call = await axios.post(url, data, { headers });
    const noteId = call.data._embedded.items[0].id;



    return {
        noteId,
        answered_user_id,

    };
};