我正在使用Node.js telegram-bot-api.
理念:
这是我正在使用的代码:
bot.sendMessage({
text: 'Please give us your phone number',
reply_markup: JSON.stringify({
keyboard: [
[{
text: 'Share my phone number',
request_contact: true
}]
],
resize_keyboard: true,
one_time_keyboard: true
})
});
Run Code Online (Sandbox Code Playgroud)
问题:
request_contact旗帜时,one_time_keyboard工作正常(使用后隐藏按钮),但即使在这种情况下它只是隐藏按钮,因此用户可以点击图标将其带回屏幕,这根本不是好事.如果我在这里做错了,请告诉我.谢谢
首先,这没有帮助.
比方说,我们有一个用户模型:
const schema = new mongoose.Schema({
active: { type: Boolean },
avatar: { type: String }
});
const User = mongoose.model('User', schema);
Run Code Online (Sandbox Code Playgroud)
当我们更新它(设置一个头像):
// This should pass validation
User.update({ _id: id }, { $set: { avatar: 'user1.png' } });
Run Code Online (Sandbox Code Playgroud)
我们希望根据当前(或更改的)active属性值对其进行验证.
active 是 falseactive 是 trueconst schema = new mongoose.Schema({
active: { type: Boolean },
avatar: …Run Code Online (Sandbox Code Playgroud) 有没有办法在Sails控制器中定义的每个和所有操作之前执行操作/功能?类似于beforeCreate模型中的钩子.
例如,在我的DataController中,我有以下操作:
module.exports = {
mockdata: function(req, res) {
var criteria = {};
// collect all params
criteria = _.merge({}, req.params.all(), req.body);
//...some more login with the criteria...
},
getDataForHost: function(req, res) {
var criteria = {};
// collect all params
criteria = _.merge({}, req.params.all(), req.body);
//...some more login with the criteria...
}
};
Run Code Online (Sandbox Code Playgroud)
我可以做以下事情:
module.exports = {
beforeAction: function(req, res, next) {
var criteria = {};
// collect all params
criteria = _.merge({}, req.params.all(), req.body);
// store …Run Code Online (Sandbox Code Playgroud) javascript ×2
node.js ×2
mongodb ×1
mongoose ×1
orm ×1
sails.js ×1
telegram ×1
telegram-bot ×1
validation ×1
waterline ×1