const express = require("express");
const app = express();
const textNow = require('textnow-api');
app.use(express.static("public"));
app.get("/", function(request, response) {
textNow.login("email", "'password").then(client => {
console.log(`Logged in as ${client.username}`);
textNow.fetchMessages(client.id, client.username).then(messages => {
console.log(messages.map(message => `ID: ${message.id} | Message: ${message.message} | Sender: ${message.contact_value}`).join('\n'));
});
});
});
const listener = app.listen("80", function() {
console.log("Your app is listening on port " + listener.address().port);
});
It only responds with a 400 error, even though I have the correct login. Can anyone please help me with this, or is it depricated and not working anymore?
textnow-api is deprecated you can use it textbelt or Twilio api
Related
I have been searching for a long time how I can send a discord message to my site.
then i found the express, i don't understand how to print data to site when discord message event is triggered can you help with this issue?
I just tried the following but it only works once and then it doesn't work again
const {Client} = require("discord.js")
const client = new Client({intents: ["GUILDS","GUILD_MEMBERS","GUILD_MESSAGES","GUILD_PRESENCES"]})
client.login("token")
client.on("ready", () => {
console.log("oks")
})
const express = require("express")
var app = express();
client.on("message", message => {
app.get("/",function(qu,res){
res.send(message.content)
})
})
})
let servers = app.listen(3000,function(){
})
Use messageCreate because the message event is depreciated. app.get() should be defined outside your message event listener. I'm not sure what you mean by "print data to site", but you can add every message sent to a database or maybe a JSON file if you'd like, and send that data through express. If you want messages on your site updated in real-time look into sockets.
Here's an example of what I mean:
const { Client } = require("discord.js")
const express = require("express")
const client = new Client({ intents: ["GUILD_MESSAGES"] })
const app = express();
const messages = []
app.get("/", (req, res) => {
res.status(200).json(messages)
})
client.on("ready", () => {
console.log("ready!")
})
client.on("message", message => {
messages.push(message)
})
client.login("token")
app.listen(3000, () => console.log("listening on port 3000")
I am trying to integrate WhatsApp and Slack for developing a chatbot. I am using WATI as my WhatsApp API provider and Slack Web API in Node.js
For testing locally I am ngrok to generate a webhook URL. But I am unable to receive WhatsApp incoming messages as it gives the following error:
process.nextTick(function () { throw userError; });
Error: Slack request signing verification failed
server.js
require('dotenv').config('/.env')
const express = require("express")
const app = express()
const PORT = process.env.PORT || 8000
const token = process.env.SLACK_BOT_TOKEN
const eventsApi = require('#slack/events-api')
const slackEvents = eventsApi.createEventAdapter(process.env.SLACK_SIGNING_SECRET)
const { WebClient, LogLevel } = require("#slack/web-api");
const client = new WebClient(token, {
logLevel: LogLevel.DEBUG
});
app.use('/', slackEvents.expressMiddleware())
//Route for WhatsApp
app.post('/wa-slack', async (req, res) => {
console.log(req)
});
slackEvents.on("message", async (event) => {
console.log(event)
// if (!event.subtype && !event.bot_id)
// client.chat.postMessage({
// token,
// channel: event.channel,
// thread_ts: event.ts,
// text: "Hello World!"
// })
})
app.listen(PORT, () => {
console.log(`App listening at http://localhost:${PORT}`)
})
The signing secret for slack is correct because the server runs successfully if I remove the following block
app.post('/wa-slack', async (req, res) => {
console.log(req)
});
Is there a way I can use the express server for handling both Slack and WhatsApp incoming requests?
Or do I need to create separate servers?
Any help or advice is appreciated, Thank you!
Hello I am new in node js and i am Facing the error.
fb-downloader package is working fine with console.log()
But i want to display results on webpage. But the Express displays only {}
Please Help me.
const getFBInfo = require("fb-downloader");
const express = require("express");
const app = express();
const port = 3016;
app.get("/",function(req, res){
data = getFBInfo("https://www.facebook.com/watch?v=272591278381388");
res.json(data);
});
app.listen(port, function() {
console.log(`Server is listening on port http://localhost:${port}!`)
});
Sorry for Bad English
getFBInfo is an asynchronous operation, therefore use async and await:
app.get("/",async function(req, res){
var data = await getFBInfo("https://www.facebook.com/watch?v=272591278381388");
res.json(data);
});
I have been trying to connect my express app, but for some reason it is just not connecting.
I am going to "IP:PORT" on chrome and I get a typical "Refused to connect" error.
I am using node.js, and the latest version of express.
"Received" does not print to the console, however it logs "App listening on port 8088"
I have tried a lot of things, hosting on digital ocean, no connection. I am currently trying it in VSC (Ip address is my ipv4 address)
When trying using HTTP, I get a connect fail error.
My code:
const express = require('express');
const app = express()
app.use(express.json())
const fs = require('fs');
require('dotenv').config()
const serverKey = process.env.SERVER_KEY
const port = process.env.PORT
function randomString(length, chars) {
var result = '';
for (var i = length; i > 0; --i) result += chars[Math.floor(Math.random() * chars.length)];
return result;
}
module.exports = {
async execute(client) {
console.log('Test')
app.post("/getVerificationCode", function (req, res, next) {
console.log("Recieved")
if (req.body.serverKey !== serverKey) {
console.log("Invalid serverKey supplied.")
return res.status(403).json({
error: "You do not have permission to use this."
})
}
let verificationCode = randomString(4, '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ').toUpperCase()
const userID = parseInt(req.body.userid)
console.log(verificationCode)
client.verificationCodes[userID] = {
code: verificationCode
}
fs.writeFile("./codes.json", JSON.stringify(client.verificationCodes, null, 4), err => {
if (err) throw err
})
return res.status(200).json({
VerificationCode: verificationCode
})
})
app.get("/*", function (req, res, next) {
return res.status(200).json({})
})
app.listen(port)
console.log(`App listening on port ${port}`)
}
}
"Test" does log, so the module IS being required. Before, I was trying it in my server.js, but that did not work and the code was messy, so I moved it into a folder.
I would really appreciate some help, thank you!
Hi Please see below sample code.
const express = require('express')
const app = express()
var port = process.env.PORT || 3000;
var appmetrics = require('appmetrics');
var monitor = appmetrics.monitor();
appmetrics.enable('http');
appmetrics.enable('request');
monitor.on('request', function (request) {
console.log('request', request);
});
monitor.on('http', function (http) {
console.log('http', http);
});
app.get('/', function (req, res) {
res.send('Hello World!')
})
app.listen(port, function () {
console.log('Example app listening on port 3000!')
})
'
Whenever I fire localhost:3000 from browser. I get 'Hello World!' reply but logs doesn't show any request or http event. Can somebody help me to point out issue.
I am using latest appmetrics version.
Thanks in Advance.
Have you tried putting line 4 (the appmetrics require line) at the top of the code? If it works, please close the issue you raised https://github.com/RuntimeTools/appmetrics/issues/452