问题
I am using ms bot framework and created a new bot. and deployed the bot connector part on the google firebase functions. But below code does not respond. Below is the code:
const builder = require('botbuilder');
const teams = require('botbuilder-teams');
import * as util from 'util';
const restify = require('restify');
let connector = new teams.TeamsChatConnector({
appId: 'my app id',
appPassword: 'my app secret'
});
var server = restify.createServer();
server.listen(80, function () {
console.log('%s listening to %s', server.name, util.inspect(server.address()));
});
server.post('/api/messages', connector.listen());
new builder.UniversalBot(connector, function (session:any) {
console.log("inside bot got something dude:::::" + session.message.text);
});
the end point in bot settings is configured as:
https://us-central1-xxxx.cloudfunctions.net/api/messages
Expected Behavior: when i send a message to the bot using bot tester then i should be able to see console message "inside bot got something dude:::::" in the firebase functions log.
however, it is never invoked so i am not sure what is missing here.
If you are wondering why we are using google firebase functions rather azure then the answer is we use firebase DB and our bot response need to go into the same firedb. Also we dont have to pay/subscribe for one more cloud just to run a simple node base code.
回答1:
Not sure if this is the issue, but all my Firebase Functions are called using the format
https://us-central1-name_of_app.cloudfunctions.net/name_of_function
whereas you're calling it using the format
https://us-central1-name_of_app.cloudfunctions.net/api/name_of_function
(with the added /api/
) which makes it seem like you're calling another website and not the actual function.
You can find the URL your function is hosted at in the main Firebase Functions page by the way.
Hopefully that helps!
回答2:
From my answer to your other question: Deploying microsoft bots nodejs to firebase functions
I got the echo bot sample to work as a Firebase function. The files from the sample should all go in your
functions
folder with index.js, bot.js, and .env being the important ones. I made some modifications to index.js so that it usesexpress
and notrestify
, though it's unclear if that's really necessary. My final index.js looks like this (note the use of thefirebase-functions
package):const functions = require('firebase-functions'); const dotenv = require('dotenv'); const path = require('path'); const express = require('express'); // Import required bot services. // See https://aka.ms/bot-services to learn more about the different parts of a bot. const { BotFrameworkAdapter } = require('botbuilder'); // This bot's main dialog. const { EchoBot } = require('./bot'); // Import required bot configuration. const ENV_FILE = path.join(__dirname, '.env'); dotenv.config({ path: ENV_FILE }); // Create adapter. // See https://aka.ms/about-bot-adapter to learn more about how bots work. const adapter = new BotFrameworkAdapter({ appId: process.env.MicrosoftAppId, appPassword: process.env.MicrosoftAppPassword }); // Catch-all for errors. adapter.onTurnError = async (context, error) => { // This check writes out errors to console log .vs. app insights. console.error(`\n [onTurnError]: ${error}`); // Send a message to the user await context.sendActivity(`Oops. Something went wrong!`); }; // Create the main dialog. const bot = new EchoBot(); // Listen for incoming requests. const app = express(); app.post('/api/messages', (req, res) => { adapter.processActivity(req, res, async (context) => { // Route to main dialog. await bot.run(context); }); }); // Expose Express API as a single Cloud Function: exports.bot = functions.https.onRequest(app);
Your bot's Microsoft app ID and password will need to be in the .env file because they're used to authenticate requests to and from Microsoft Teams. In order to do this, the bot must make requests to an external token server which is naturally not a part of Google. You'll need a paid plan in order for your function to call an external API like that, as you can see here: Use firebase cloud function to send POST request to non-google server
With a free plan, you can still test the function locally with firebase emulators:start. However, it sounds like you already have a paid plan so I believe this shouldn't be a problem for you. Whether running your bot locally or deployed, your endpoint should end with
/bot/api/messages
(if you use "bot" as your function name like I have). Once you deploy your bot, you can use the deployed endpoint in the settings blade of your bot resource in Azure.
As you can see, you can't just deploy anything to Firebase. You need to include specific Firebase-related code in order to establish the specific cloud functions that are meant to run on Firebase.
来源:https://stackoverflow.com/questions/57446390/microsoft-bot-does-not-respond-back-from-firebase-cloud-function