deploy bot without hosting on azure - node.js

I have created a bot using Microsoft bot framework (NodeJs) , it working fine on local system. When i deployed with azure functions then also its working fine.
But i'm trying to deploy in some other way like
1) I want to register my bot on azure
2) but want to host somewhere else(SSL Certified server) i.e not on azure (don't want to use azure bot functions)
I have followed the steps got in some articles
My App.js Looks like this
But i'm getting below error when i tried to test with "Test in web Chat"
Can anyone please help me, what i'm doing wrong here ??
Thanks

Not familiar with AWS, but for making restify server support HTTPS, you can try to use:
const restify = require('restify');
const fs = require('fs');
const https_options = {
key: fs.readFileSync('./localhost_3978.key'), //on current folder
certificate: fs.readFileSync('./localhost_3978.cert')
};
server = restify.createServer(https_options);
Create the restify server with your SSL certificate and key files before your bot application.

Related

How to access firebase database from nodejs admin sdk after enforcing Firebase App Check

I have enabled Firebase App Check in my project to ensure all requests are coming only from our app. That has been working well till now (Using RecaptachaV3 as a Attestation Provider for web). However I want to access the database (rtdb) from my backend nodejs server. I'm using the firebase-admin-sdk with a service account for it. But I am unable to do it.
const { initializeApp, applicationDefault } = require('firebase-admin/app');
const { getDatabase } = require('firebase-admin/database');
const app = initializeApp({
credential: applicationDefault(),
databaseURL: '********',
});
const db = getDatabase(app);
const ref = db.ref('/some-path');
ref.once('value', (snapshot) => {
console.log(snapshot.val());
});
Below error is thrown
[2022-06-27T09:42:25.299Z] #firebase/database: FIREBASE WARNING: Missing appcheck token (https://qtalkproject.firebaseio.com/)
Isn't app check only for clients? Shouldn't firebase allow all requests that are coming from a service account? Why is it asking for an app check token? Acc to the documentation the firebase-admin-sdk is allowed to create app check tokens. If it is allowed to create app check tokens, doesn't it mean it is already authenticated? Why can't I access the database from the same admin sdk then? Am I missing something here?
If anyone else is blocked like me until firebase releases the fix, you can use the older version of the firebase admin sdk which doesn't have app check (I used v9.3.0) to access rtdb and other firebase features
Firebaser here
You are correct, the Firebase Admin SDK should bypass App Check. Thank you for finding and reporting this bug! Our team has identified the issue and currently working on a fix. We will use the following GitHub issue to track the progress https://github.com/firebase/firebase-admin-node/issues/1788

Installing an SSL cert for NodeJs express (for API) on my Windows server

all my servers are hosted locally. I use IIS on server 2019 to host and manage my website. I use NodeJs to act as an API which makes queries to my SQL server to get the information and return it to my React app.
my react app calls out to my NodeJs API using fetch url
var url = 'https://example.com:8080/api/locationInfo/client?client=%';
fetch(url, {agent})
.then(response => response.json())
.then(data => setLocationInfoData(data));
since my website is using HTTPS, i must use that in the URL that reaches out to the API service from NodeJs.
right now when i attempt to make these API calls, console is giving me the error: net::ERR_SSL_PROTOCOL_ERROR
im assuming this is because my NodeJs app does not have an SSL certificate installed.
I've spent many (many) hours of research, but im not experienced with the backend of web development and im having trouble understanding where and how i apply an SSL cert to my NodeJs API. I used IIS to create a self-signed certificate, but it hasnt been applied anywhere and nothing else was done; im not sure where to go from here.
if it matters, my NodeJS API is hosted on the C:\Program Files[...] directory of the server, not under the actual web hosted directories.
If i place the NodeJs app within the actual web hosted directories, would i still need a certificate? If so, how do i export the .key and the .crt files to include in my NodeJs code?
please let me know if i can provide any more information or any of my code. My experience is limited, but im determined to learn and just need some pointers to send me in the right direction.
EDIT: i created a PFX cert from windows and used openSSH to convert the key, ca, and cert to .pem and included those in my nodeJs application. now im getting "ERR_SSL_KEY_USAGE_INCOMPATIBLE"
nodeJS code:
const sslServer = https.createServer(
{
key: fs.readFileSync(path.join(__dirname, 'cert', 'key.pem')),
cert: fs.readFileSync(path.join(__dirname, 'cert', 'cert.pem')),
ca: fs.readFileSync(path.join(__dirname, 'cert', 'ca.pem')),
},
app
)

Download from Firebase Storage

I'm using nodejs for the download of some files (mp3) from Firebase Storage, that I will send to the client.
I want to get blob file and then send to the client.
I read the docs and Firebase use refFromURL method to get the downloadable url.
But when I start the script, it says that refFromURL is not an url:
const firebase = require('firebase-admin')
var serviceAccount = require('./api/admin.json')
firebase.initializeApp(optionFirebase)
var storageSongs = firebase.storage()
let linkSong = storageSongs.refFromURL('FILE_URL')
It's not an authentication problem because I use the same options for Realtime Database and it works well.
refFromURL is a method provided by the Firebase JavaScript web client SDK. It's not available in the Cloud Storage nodejs SDK for backends.

Microsoft Azure LUIS app emulator no reply

Just set up a Azure Bot essentially following this tutorial https://learn.microsoft.com/en-us/azure/cognitive-services/luis/luis-nodejs-tutorial-build-bot-framework-sample and the code works fine when I test it in the online web chat - intent is recognised and the bot responds.
However, when I try to run the same code copied down and set up as a local git repository through Visual Studio Community 2017, the bot doesn't seem to reply.
I'm not hitting any errors right now when I send the bot a message through the emulator (chatconnector registers it as message received).
Any ideas on how to fix this?
http://i1376.photobucket.com/albums/ah21/michael_liang1/stack%20overflow_zpsrvsazqvt.png
(don't have enough reputation to post images yet - sorry!)
It's possible that you didn't configure the LuisAppId, LuisAPIKey and LuisAPIHostName in the .env file when you copy the code into the local VS.
In portal, it will automatically get these keys from app settings, but on local side, we need to configure them in our code.
According to the tutorial, the LuisAppId, LuisAPIKey and LuisAPIHostName should be configured in .env, for example like this:
# Bot Framework Variables
MICROSOFT_APP_ID=<YOURAPPID>
MICROSOFT_APP_PASSWORD=<YOURAPPPASSWORD>
LuisAppId=<YOURLUISAPPID>
LuisAPIKey=<YOURLUISKEY>
LuisAPIHostName=<YOURAPIHOSTNAME>
Then the code in toturial uses these three parameters to generate a LuisModelUrl, you can actually directly configure this url which is generated after you publish your luis app, into your .env file. For more information, you can refer to the official LUIS Bot Sample.
Solved the issue. It seems you need to add parameters into the AzureTableClient method of botbuilder SDK to include the name and key of an existing storage account hosted in Azure.
var tableName = 'botdata';
var azureTableClient = new botbuilder_azure.AzureTableClient(tableName, process.env.AzureTableName, process.env.AzureTableKey); //process.env['AzureWebJobsStorage']
var tableStorage = new botbuilder_azure.AzureBotStorage({ gzipData: false }, azureTableClient);
I added process.env.AzureTableName and process.env.AzureTableKey which is the name and access key for the Azure Storage Account I created. The variables key and name are specified in my .env file.

access SSL certificate in Azure Web App

I've uploaded an SSL certificate to my Azure Web App, running on Node, and now I'd like to access my certificate programmatically from my Node scripts to use it for signing JWTs. Is there a way to do this?
I've found similar answers for C#, but I haven't been able to translate this into Node-world.
Update
Here is code that worked successfully, with help from #peter-pan-msft. Before running this code, I had to SFTP upload my SSL certificate to a private folder on the server.
process.env.KEY = fs.readFileSync('path-to-private-folder/mykey.pem');
const jwt = require('jsonwebtoken');
const token = jwt.sign(payload, process.env.KEY, opts);
There are two samples separately from AzureAD on GitHub and azure-mgmt on npmjs.org.
https://github.com/AzureAD/azure-activedirectory-library-for-nodejs/blob/master/sample/certificate-credentials-sample.js
https://www.npmjs.com/package/azure-mgmt
If you want to use the certification for doing Azure Management, you can directly refer to the second sample.

Resources