Scope Scope - 1 month ago 11
Javascript Question

Kik Bot | Uncaught ReferenceError: require is not defined

I'm trying to create a kik bot, but I keep getting this error anytime I try and run it "Uncaught ReferenceError: request is not defined". I have installed node and the kik package but that seems not to be working here is my Javascript:

request.post({
url: "https://api.kik.com/v1/config",
auth: {
user: "<my-user-name>",
pass: "<my-api-key>"
},
json: {
"webhook": "<link>",
"features": {
"receiveReadReceipts": false,
"receiveIsTyping": false,
"manuallySendReadReceipts": false,
"receiveDeliveryReceipts": false
},
"staticKeyboard": {
"type": "suggested",
"responses": [
{
"body": "Start",
"type": "text"
},
{
"body": "Help",
"type": "text"
}
]
}
}
}, callback);


I've been trying to looking into this but came up with nothing. Could it be a Node problem?

Thank you in advance!!

Answer

From the conversation we had, I thought I put the answer here for future references.

That piece of code is supposed to be run on NodeJS in commandline, not a browser.

You need to setup a node environment, install the required dependencies using npm or whatever you like. Then run the code in node.

$ npm install request to install request. var request = require('request') to require the installed library.

Also you need to modify the code and provide proper a callback function. You can read requests documentation here.