Q:

Docusign embedded signing request from template with nodejs

I am using the nodejs docusign api and am having trouble figuring out how do embedded signing request from template. I kinda want it working the way the example does for non template usage.
The main issue i am having is with the way the nodejs docusign library handles recipientIds when you are using a template, cant set the recipientIds directly when you use the template and doesnt seem to take the recipients set automatically by docusign
Most of my code wasfollowing the quickstart guide
Yes I have read, but found the answers unhelpful.
Docusign embedded signing request from template and Docusign Embedded Signing using template

A:

    function makeEnvelope(args){
        // create the envelope definition
        let env = new docusign.EnvelopeDefinition();
        env.templateId = args.templateId;
    
        // Create template role elements to connect the signer and cc recipients
        // to the template
        // We're setting the parameters via the object creation
        let signer1 = docusign.TemplateRole.constructFromObject({
            email: args.signerEmail,
            name: args.signerName,
            clientUserId: '1',
            roleName: 'signer'});
    
    
        // Add the TemplateRole objects to the envelope object
        env.templateRoles = [signer1];
        env.status = "sent"; // We want the envelope to be sent
    
        return env;
    }
    
    {
       let dsApiClient = new docusign.ApiClient();
        dsApiClient.setBasePath(args.basePath);
        dsApiClient.addDefaultHeader('Authorization', 'Bearer ' + args.accessToken);
        let envelopesApi = new docusign.EnvelopesApi(dsApiClient);
        
        // Step 1. Make the envelope request body (function above)
        let envelope = makeEnvelope(args.envelopeArgs)
    
        // Step 2. call Envelopes::create API method
        // Exceptions will be caught by the calling function
        let results = await envelopesApi.createEnvelope(
            args.accountId, {envelopeDefinition: envelope});
    
        return results;
    }

function makeRecipientViewRequest(args) {

    let viewRequest = new docusign.RecipientViewRequest();

    viewRequest.returnUrl = args.dsReturnUrl + "?state=123";

    viewRequest.authenticationMethod = 'none';
    
    viewRequest.email = args.signerEmail;
    viewRequest.userName = args.signerName;
    viewRequest.clientUserId = args.signerClientId;

    viewRequest.pingFrequency = 600; // seconds
    viewRequest.pingUrl = args.dsPingUrl; // optional setting

    return viewRequest
}

