Zenia Lomas
Zenia Lomas

Reputation: 11

Direct CloudFunctions call was not successful. Http response code is [401]

I'm trying to send reminders to my watson assistant. The code works fine on the cloud. However when I integrated to my watson assistant I get the following runtime errors: Direct CloudFunctions call was not successful. Http response code is [401]. Direct CloudFunctions call was not successful. Response is [The supplied authentication is invalid].

var nodemailer = require('nodemailer');
let smtpConfig = {
host: 'smtp.gmail.com', // you can also use smtp.gmail.com
port: 465,
secure: true, // use TLS
auth: {
    user: 'myuser@', 
    pass: 'passwd'
}
};

function main(params) {
return new Promise(function (resolve, reject) {
    let response = {
        code: 200,
        msg: 'E-mail was sent successfully!'
    };

    if (!params.reminder) {
        response.msg = "Error: Reminder was not provided.";
        response.code = 400;
    }
    else if (!params.email) {
        response.msg = "Error: Destination e-mail was not provided.";
        response.code = 400;
    }
    else if (!params.conversation_id) {
        response.msg = "Error: Conversation id was not provided.";
        response.code = 400;
    }

    if (response.code != 200) {
        reject(response);
    }

    console.log(`Validation was successful, preparing to send email...`);

    sendEmail(params, function (email_response) {
        response.msg = email_response['msg'];
        response.code = email_response['code'];
        response.reason = email_response['reason'];
        console.log(`Email delivery response: (${email_response['code']}) ${response.msg}`);
        resolve(response);
    });

});
}

function sendEmail(params, callback) {

let transporter = nodemailer.createTransport(smtpConfig);
let mailOptions = {
    from: `Watson Assistant Emails <${smtpConfig.auth.user}>`,
    to: params.email,
    subject: `Subject ${params.reminder}`
};
transporter.sendMail(mailOptions, function (error, info) {

    let email_response = {
        code: 200,
        msg: 'Email was sent successfully',
        reason: 'Success'
    };

    if (error) {
        email_response.msg = 'Error';
        email_response.code = 500;
        email_response.reason = error;
    }
    else {
        email_response.msg = info.response;
        email_response.code = 200;
        email_response.reason = info.response;
    }
    callback(email_response);
});

}

I can execute the code fine on the cloud but when I integrate it it's showing me those errors

Here is my assistant reponds code in the chatbot

{
"output": {
"generic": []
},
 "actions": [
{
  "name": "Natureplex_email/examples/send-email-reminder",
  "type": "server",
  "parameters": {
    "email": "$destination_email",
    "reminder": "$reminder",
    "conversation_id": "$conversation_id"
  },
  "credentials": "$private.cf_creds",
  "result_variable": "context.cf_response"
}
]
}

Upvotes: 0

Views: 62

Answers (0)

Related Questions