registerPlugin({
name: 'Welcome!',
version: '1.0',
description: 'This plugin will let the bot greet everyone.',
author: 'Michael Friese',
vars: {
message: {
title: 'The message that should be displayed. (%n = nickname)',
type: 'string'
}
}
}, function(sinusbot, config) {
sinusbot.on('chat', function(ev) {
if (ev.msg == "!http") {
$.ajax({
url: "https://google.com",
type: 'POST',
data: example_parameters
});
}
});
});
That's not
Example
Code:registerPlugin({ name: 'Welcome!', version: '1.0', description: 'This plugin will let the bot greet everyone.', author: 'Michael Friese', vars: { message: { title: 'The message that should be displayed. (%n = nickname)', type: 'string' } } }, function(sinusbot, config) { sinusbot.on('chat', function(ev) { if (ev.msg == "!http") { $.ajax({ url: "https://google.com", type: 'POST', data: example_parameters }); } }); });
You can't use jQuery in scripts.this seems to be a jquery function. for that to function, you will have to load the library first
sinusbot.http({
method: 'POST',
url: 'http://127.0.0.1:8087/api/v1/bot/login',
timeout: 6000,
maxSize: 1024*1024*5,
headers: {
"Content-Type": "application/json",
"Accept": "application/json"
},
body: '{"username": "user", "password": "pass", "botId": "botId"}'
}, function(error, response) {
var botToken = JSON.parse(response.data)['token'];
engine.log('Retrieved token '+botToken);
});
Better would be application/json - the api only speaks jsonheaders: { "Content-Type": "text/plain", "Accept": "text/plain" }
That's good to know. Thanks for pointing it out! I edited my first answer.Better would be application/json - the api only speaks json
Quick Tipp: While using POST,PUT and PATCH (any request with a body of size x) requests you have to set also a Content-Length.
That's good to know. Thanks for pointing it out! I edited my first answer.
Is setting content-length really required when also defining maxSize?
maxSize: 1024*1024*5,
ar baseUrl = 'https://smsapi.free-mobile.fr/sendmsg';
function smsautomate(msg){
sinusbot.http({
method: 'POST',
url: baseUrl,
timeout: 6000,
maxSize: 1024*1024*5,
headers: {
"Content-Type": "application/json",
"Accept": "application/json"
},
body: '{"user": "secret", "pass": "secret", "msg": "{"name": "test","pseudo": "test","msg": "'+msg+'"}"}'
},function(error, response) {
for(var key in response){
if(typeof response[key] !== 'object'){
userdebug.chat(key+':'+response[key]);
}
if(typeof response[key] === 'object'){
for(var key0 in response[key]){
userdebug.chat(key+':'+key0+':'+response[key][key0]);
}
}
}
});
}
smsautomate('msg test');