• If you need help or want to discuss things, you now can also join us on our Discord Server!
  • A first preview of the unlimited version of SinusBot can be found in the Upcoming Changes thread. A version for Windows will follow, but we don't have a release date, yet.

EN How to http request script?

Status
Not open for further replies.

Yasin

Member
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
            });
        }
    });
});
 
Last edited:

vincolus

Donor
is awesome!
Contributor
Insider
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
            });
        }
    });
});

this seems to be a jquery function. for that to function, you will have to load the library first
 

vincolus

Donor
is awesome!
Contributor
Insider
I am posting this here so it does not get lost in case links expire:

Code:
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);
});

This post was edited on behalf of Xuxes answer.
 
Last edited:

Xuxe

Containerholic
Staff member
is awesome!
V.I.P.
Contributor
Insider
headers: { "Content-Type": "text/plain", "Accept": "text/plain" }
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.
 

vincolus

Donor
is awesome!
Contributor
Insider
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?
 

Xuxe

Containerholic
Staff member
is awesome!
V.I.P.
Contributor
Insider
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?

Content-Length is definitly related to your body, some server's deny requests when a client send's a body without a Content-Length.

maxSize: 1024*1024*5,

If i am right maxSize is related to the max response size the server can send, remember badboys can send you Gigabytes of response data ;)
 

Schaeffer

Donor
is awesome!
I do not understand where I made a mistake
it returns me error 400: One of the required parameters is missing.
JavaScript:
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');
 

flyth

is reticulating splines
Staff member
Developer
Contributor
The json you send is garbage :) looks like you want to send json in json - that needs to be escaped properly.
 

Schaeffer

Donor
is awesome!
résolut opérateur gratuit avec la méthode si ci-dessus ne supporte pas du tout le json sinon il me renvoie par sms hash (uncoderendom)
ducoup j'ai utilisé l'ancienne metode du compteur dans l'url le json.stringify (l'objet)
Thankyou
 
Status
Not open for further replies.
Top