I’ve deploy my node.js server into Azure by new AppService linux. It correctly start, because if I call one http get it return the correct data. But when I try to call the post url that make a:
server.post('/api/messages', (req, res) => { adapter.processActivity(req, res, async (context) => { // Process bot activity await botActivityHandler.run(context).catch((e) => { console.dir(e) }); });)}
it return
UnhandledPromiseRejectionWarning: Error: BotFrameworkAdapter.processActivity(): 400 ERROR Error: BotFrameworkAdapter.parseRequest(): missing activity type.
I’ve already check if the bot have the correct appId and pwd, and it’s are ok.
This is my index.js file:
// index.js is used to setup and configure your bot const path = require('path'); const express = require('express'); const bodyParser = require('body-parser'); // Import required bot services. // See https://aka.ms/bot-services to learn more about the different parts of a bot. const { BotFrameworkAdapter } = require('botbuilder'); // Import bot definitions const { BotActivityHandler } = require('./botActivityHandler'); // Read botFilePath and botFileSecret from .env file. const ENV_FILE = path.join(__dirname, '.env'); require('dotenv').config({ path: ENV_FILE }); // Create adapter. const adapter = new BotFrameworkAdapter({ appId: "XXXXXXXXXXXXXXXXXXXXXX", appPassword: "XXXXXXXXXXXXXXXXXXXXXXX" }); adapter.onTurnError = async (context, error) => { console.error(`unhandled error: ${error}`); console.dir(`unhandled error: ${error}`); await context.sendTraceActivity( 'OnTurnError Trace', `${error}`, 'https://www.botframework.com/schemas/error', 'TurnError' ); await context.sendActivity('The bot encountered an error or bug.'); await context.sendActivity('To continue to run this bot, please fix the bot source code.'); }; // Create bot handlers const botActivityHandler = new BotActivityHandler(); // Create HTTP server. const server = express(); server.use(function (req, res, next) { res.header("Access-Control-Allow-Origin", "*"); res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization"); res.header('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE, OPTIONS'); next(); }); server.use(bodyParser.json()); // to support JSON-encoded bodies server.use(bodyParser.urlencoded({ // to support URL-encoded bodies extended: true })); const port = process.env.port || process.env.PORT || 3978; server.listen(port, () => console.log(`service listening at https://localhost:${port}`) ); // Listen for incoming requests. server.post('/api/messages', (req, res) => { console.dir(adapter); adapter.processActivity(req, res, async (context) => { // Process bot activity console.dir(context); await botActivityHandler.run(context).catch((e) => { console.dir(e) }); }); }); server.post('/api/create/uat', (req, res) => { console.dir(req.params); }); server.get('/api/read/uat', (req, res) => { console.dir(req.params); }); server.post('/api/prova/post', (req, res) => { console.dir(req.params); });
Locally with ngrok it run ok, Can anyone help me? Thanks.
Advertisement
Answer
As suggested by @Leonardo, Local and distributed app can be deleted and setup a new app by changing the URL.