Messenger bot - 示例代码

时间:2017-02-25 14:16:07

标签: node.js bots facebook-messenger

我正在尝试创建一个机器人。使用这个项目。我的设置如下:

Amazon EC2实例。我创建了sub-domain.domain.com我添加了ssl认证。我已将子域指向/var/www/sub-domain/

我已经安装了解压缩并在/var/www/sub-domain/project/中安装了项目我已经配置了项目并正确运行它:

节点应用正在端口5000上运行

如果我访问http://sub-domain.domain.com:5000,我可以访问项目公共索引。我理解这意味着端口是打开的,节点应用程序可以工作。

现在当我尝试在facebook中配置我的webhook时,我不明白要使用的url callbak。根据我在配置中的理解,服务器URL应为https://sub-domain.domain.com,配置应该有效。但它没有。

我应该使用什么网址?

2 个答案:

答案 0 :(得分:0)

您的回调网址应该是您发送用户数据的实际文件。就像你使用PHP一样,你要说:http://yourhost/chatbot.php。目前,webhook将是您的节点应用正在监听的URL。

答案 1 :(得分:0)

您的webhook需要一个可访问的URL。我不知道您使用的是哪个示例代码,但我的猜测是,根据您当前的设置,您应该使用http://sub-domain.domain.com/webhook

您可以使用Apache或Nginx在ProxyPass(端口80)上使用proxy_pass / public class Graph { /*The following square matrix represents a weighted undirected graph. the value in (i,j) position indicates the cost between i and j node. Zeros indicate no connection*/ static int[][] matrix = { { 0, 3, 0, 2, 0, 0, 0, 0, 4 }, // 0 { 3, 0, 0, 0, 0, 0, 0, 4, 0 }, // 1 { 0, 0, 0, 6, 0, 1, 0, 2, 0 }, // 2 { 2, 0, 6, 0, 1, 0, 0, 0, 0 }, // 3 { 0, 0, 0, 1, 0, 0, 0, 0, 8 }, // 4 { 0, 0, 1, 0, 0, 0, 8, 0, 0 }, // 5 { 0, 0, 0, 0, 0, 8, 0, 0, 0 }, // 6 { 0, 4, 2, 0, 0, 0, 0, 0, 0 }, // 7 { 4, 0, 0, 0, 8, 0, 0, 0, 0 } // 8 }; /* static int[][] matrix = { { 0, 2, 3, 0, 0 }, // 0 { 2, 0, 15, 2, 0 }, // 1 { 3, 15, 0, 0, 13}, // 2 { 0, 2, 0, 0, 9}, // 3 { 0, 0, 13, 9, 0}, // 4 }; */ static int Node = matrix.length; static int[][] Edge = new int[Node][Node]; static int NotConnected = 999999; public static void MakeGraph() { for (int i = 0; i < Node; i++) { for (int j = 0; j < Node; j++) { Edge[i][j] = matrix[i][j]; if (Edge[i][j] == 0)// If Node i and Node j are not connected Edge[i][j] = NotConnected; } } // Print the graph representation matrix. for (int i = 0; i < Node; i++) { for (int j = 0; j < Node; j++) if (Edge[i][j] != NotConnected) System.out.print(" " + Edge[i][j] + " "); else // when there is no connection System.out.print(" * "); System.out.println(); } } public static void Prim(){ System.out.println("OUPUT OF PRIM'S ALGORITHM:"); // Write the code for Prim algorithm to find the minimum cost spanning tree here // and print the result in console with the following format: /*==========================OUTPUT FORMAT=========================== Minimun Cost of Spanning Tree = "....... " Edges of the minimum cost spanning tree: ".........................................................." (for example: Edges of the minimum cost spanning tree: "0 -- 1 7 -- 2 0 -- 3 3 -- 4 2 -- 5 5 -- 6 1 -- 7 0 -- 8)" ================================================================== */ } public static void Kruskal(){ System.out.println("OUPUT OF KRUSKAL'S ALGORITHM:"); // Write the code for Kruskal algorithm to find the minimum cost spanning tree here // and print the result in console with the following format: /*==========================OUTPUT FORMAT=========================== Minimun Cost of Spanning Tree = "....... " Edges of the minimum cost spanning tree: ".........................................................." ================================================================== */ } public static void main(String[] args) { MakeGraph(); Prim(); Kruskal(); } } 指令访问它。

  

我已经安装了解压缩并在/ var / www / sub-domain / project / [...]中安装了项目我访问项目公共索引

您的项目的Javascript文件不需要和 不能被公众访问,因为它们可能包含您的应用程序的秘密ID和令牌。