我正在尝试复制facebook messenger bot,但不断获得function callSendAPI(messageData) {
request({
uri: 'https://graph.facebook.com/v2.6/me/messages',
qs: { access_token: PAGE_ACCESS_TOKEN },
method: 'POST',
json: messageData
}, function (error, response, body) {
if (!error && response.statusCode == 200) {
var recipientId = body.recipient_id;
var messageId = body.message_id;
console.log("Successfully sent generic message with id %s to recipient %s",
messageId, recipientId);
} else {
console.error("Unable to send message.");
console.error(response);
console.error(error);
}
});
}
。
与Facebook相同的代码:
server.js
我的节点const express = require('express');
const bodyParser = require('body-parser');
//const request = express.request;
const PAGE_ACCESS_TOKEN = 'abc';
let app = express();
app.use(bodyParser.urlencoded({ extended: false }));
// parse application/json
app.use(bodyParser.json());
[...]
function sendTextMessage(recipientId, messageText) {
var messageData = {
recipient: {
id: recipientId
},
message: {
text: messageText
}
};
callSendAPI(messageData);
}
function callSendAPI(messageData) {..}
[...]
如下所示:
library(tidyverse)
mt_make %>%
mutate(l = map(l, ~filter(.x, cyl == 6)),
m = map(m, ~filter(.x, hp > 150)),
n = map2(l, m, inner_join)) %>% # collect data where l and m have data
unnest(n)
#> # A tibble: 1 × 12
#> make car mpg cyl disp id hp drat wt qsec
#> <chr> <chr> <dbl> <dbl> <dbl> <int> <dbl> <dbl> <dbl> <dbl>
#> 1 Ferrari Ferrari Dino 19.7 6 145 30 175 3.62 2.77 15.5
#> # ... with 2 more variables: vs <dbl>, am <dbl>
mt_id %>%
mutate(l = map(l, ~filter(.x, make == 'Merc')),
m = map(m, ~filter(.x, hp < 200))) %>%
filter(map_int(l, nrow) == map_int(m, nrow)) %>% # assumes your data is parallel, which suggests there's no point to nesting
unnest()
#> # A tibble: 7 × 12
#> id car mpg cyl disp make hp drat wt qsec vs
#> <int> <chr> <dbl> <dbl> <dbl> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 8 Merc 240D 24.4 4 146.7 Merc 62 3.69 3.19 20.0 1
#> 2 9 Merc 230 22.8 4 140.8 Merc 95 3.92 3.15 22.9 1
#> 3 10 Merc 280 19.2 6 167.6 Merc 123 3.92 3.44 18.3 1
#> 4 11 Merc 280C 17.8 6 167.6 Merc 123 3.92 3.44 18.9 1
#> 5 12 Merc 450SE 16.4 8 275.8 Merc 180 3.07 4.07 17.4 0
#> 6 13 Merc 450SL 17.3 8 275.8 Merc 180 3.07 3.73 17.6 0
#> 7 14 Merc 450SLC 15.2 8 275.8 Merc 180 3.07 3.78 18.0 0
#> # ... with 1 more variables: am <dbl>
我是否遗漏了快递?感谢
答案 0 :(得分:3)
此示例正在使用third-party Request module。
你也可以像require('http').request()
一样使用request
,如果你愿意,但我会说, request 模块很常见,而且很好使用工具。
编辑 实际上,我只是注意到你的代码中有它,但它被注释掉了!经过更长时间的浏览后,你注释掉了express.request
指向request()
,如果像http.request
一样使用会抛出错误,因为它不是函数。因此,您应该使用Request模块,或者调整代码以使用本机/opt
。
答案 1 :(得分:0)
您未安装了request
模块。
首先npm install --save request
安装它,然后包括它var request = require('request');