Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace deprecated 'request' with 'axios' for HTTP calls #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const express = require('express');
const bodyParser = require('body-parser');
const axios = require('axios');
const { TiledeskChatbotClient } = require('@tiledesk/tiledesk-chatbot-client');

const app = express();
Expand Down Expand Up @@ -30,7 +31,7 @@ app.post('/rawbot', (req, res) => {
let request_id = tiledesk_request.request_id
let bot_name = tiledesk_request.department.bot.name;

// immediatly reply to TILEDESK
// immediately reply to TILEDESK
res.status(200).send({"success":true});

// Reply service is asynchronous.
Expand All @@ -45,19 +46,18 @@ app.post('/rawbot', (req, res) => {
"senderFullname": bot_name // you can change the chatbot name here
}

request({
url: `${endpoint}/${project_id}/requests/${request_id}/messages`,
axios.post(`${endpoint}/${project_id}/requests/${request_id}/messages`, msg, {
headers: {
'Content-Type' : 'application/json',
'Authorization': 'JWT '+token
},
json: msg,
method: 'POST'
},
function(err, res, resbody) {
console.log("Message sent.")
}
);
})
.then(response => {
console.log("Message sent.");
})
.catch(error => {
console.error("Error sending message:", error);
});
})

app.listen(3000, () => {
Expand Down