微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何使用 namecheap 创建 webhook 服务器

如何解决如何使用 namecheap 创建 webhook 服务器

我有 namecheap 共享主机,我在 cpanel 中使用了 node.js 应用程序我创建了一个http://roboters.live/shaheen 上运行的应用程序

现在我正在使用 dialogflow,我需要使用 price.js 文件将我的聊天机器人与 excel 文件连接起来,而无需使用内联编辑器

这是文件

const express = require("express")
const app = express();
const rp = require("request-promise-native")
const dfff = require("dialogflow-fulfillment")

app.post("/",express.json(),function(req,res){
    dialogflow(req,res)
})

const dialogflow = (req,res) => {
    const agent = new dfff.WebhookClient({
        request: req,response : res
    });
    
    function price(agent){
        var From = req.body.queryResult.parameters.From
        var To = req.body.queryResult.parameters.To
        var Weight = req.body.queryResult.parameters.Weight
        var url = "https://sheetdb.io/api/v1/2f53mv3d1o35c/search?From="+From+"&&To="+To
        console.log(From)
        console.log(To)
        console.log(Weight)
        console.log(url)
        return rp.get(url).then(message =>{
            const body = JSON.parse(message)
            const pricing = body[0].Price
            const price = pricing * Weight
            agent.add("Your Price Estimation is " + price + " Usd For Shipping " + Weight + " Kilos From " + From + " To " + To)
            console.log(price)
        }).catch(err =>{
            agent.add("sorry")

            
        })

    }
    var intentMap = new Map()
    intentMap.set("pricing",price)
    agent.handleRequest(intentMap)
}


app.listen(3000,function(){
    console.log("We are Live");
})

这个显示 不能得到沙欣 当我去roboters.live/shaheen

然后我使用了这段代码,我猜它很糟糕

const express = require("express")
const app = express();
const rp = require("request-promise-native")
const dfff = require("dialogflow-fulfillment")


var http = require('http');
var server = http.createServer(function(req,res) {
    res.writeHead(200,{'Content-Type': 'text/plain'});
    var message = 'It works!\n',version = 'NodeJS ' + process.versions.node + '\n',response = [message,version].join('\n');
    res.end(response);
});

const dialogflow = (req,price)
    agent.handleRequest(intentMap)
}
server.listen();

现在为什么它不起作用任何想法? 当我使用 vscode node.js 和 ngrok 时,第一个代码工作正常 但第二个代码在 namecheap 中工作,显示它在 robots.live/shaheen 中工作 但它们都没有使 dialogflow 工作,因为它没有到达服务器 有什么想法吗?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。