Commit b9338a69 authored by tug's avatar tug

First run my client

parent 73c2e0d8
node_modules/ node_modules/
*.log *.log
_td*
const http = require('http') const http = require('http')
// const tgclient = require('./tgclient')
// const logger = require('./logger')
const { Client } = require('tdl')
const { TDLib } = require('tdl-tdlib-addon')
var path = require('path');
const tgclient = new Client(new TDLib(path.join(__dirname, 'td/build/libtdjson.so')), {
apiId: 234569,
apiHash: 'ee77bf549e61d3de158916126c8ef7dd'
})
tgclient.on('error', console.error)
tgclient.on('update', update => {
console.log('Received update:', update)
})
async function main () {
await tgclient.connectAndLogin()
console.log(await tgclient.invoke({ _: 'getMe' }))
// ...
}
main().catch(console.error)
var myNumber = 1;
const host = '192.168.130.10' const host = '192.168.130.10'
const port = 51000 const port = 51000
...@@ -10,6 +39,17 @@ function notFound(res) { ...@@ -10,6 +39,17 @@ function notFound(res) {
} }
const server = http.createServer((req, res) => { const server = http.createServer((req, res) => {
//getAuthorizationState
myNumber = myNumber+1;
console.log(' ')
console.log(' ')
console.log('---=======- [ '+myNumber+' ] ---------')
console.log('This is the METHOD:' + req.method)
console.log('This is the URL:' + req.url)
console.log('This is the REQUEST Hdrs:')
console.log(req.headers)
switch (req.method) { switch (req.method) {
case 'GET': { case 'GET': {
switch (req.url) { switch (req.url) {
...@@ -25,12 +65,36 @@ const server = http.createServer((req, res) => { ...@@ -25,12 +65,36 @@ const server = http.createServer((req, res) => {
res.end('About page\n') res.end('About page\n')
break break
} }
case '/test': {
tgclient.invoke({
_: 'sendMessage',
chat_id: 124987160,
input_message_content: {
_: 'inputMessageText',
text: {
_: 'formattedText',
text: '👻 Test 123'
}
}
})
res.statusCode = 200
res.setHeader('Content-Type', 'text/plain')
res.end('About page\n')
break
}
case '/': {
res.statusCode = 200
res.setHeader('Content-Type', 'text/plain')
res.end('Hello main\n')
break
}
default: { default: {
notFound(res) notFound(res)
break break
} }
} }
break break
} }
case 'POST': { case 'POST': {
......
const winston = require('winston')
const options = {
file: {
level: 'info',
filename: './logs/app.log',
handleExceptions: true,
json: true,
maxsize: 50242880, // 5MB
maxFiles: 5,
colorize: true,
},
console: {
level: 'debug',
handleExceptions: true,
json: false,
colorize: true,
},
};
const logger = winston.createLogger({
levels: winston.config.npm.levels,
transports: [
new winston.transports.File(options.file),
new winston.transports.Console(options.console)
],
exitOnError: false
})
module.exports = logger
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -20,7 +20,13 @@ ...@@ -20,7 +20,13 @@
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"express": "^4.18.1", "express": "^4.18.1",
"http": "^0.0.1-security" "http": "^0.0.1-security",
"morgan": "^1.10.0",
"morgan-json": "^1.1.0",
"pm2": "^5.2.0",
"tdl": "^7.1.0",
"tdl-tdlib-addon": "^1.2.1",
"winston": "^2.4.6"
}, },
"devDependencies": { "devDependencies": {
"logger-service": "^1.0.2" "logger-service": "^1.0.2"
......
const { Client } = require('tdl')
const { TDLib } = require('tdl-tdlib-addon')
var path = require('path');
const tgclient = new Client(new TDLib(path.join(__dirname, 'td/build/libtdjson.so')), {
apiId: 234569,
apiHash: 'ee77bf549e61d3de158916126c8ef7dd'
})
tgclient.on('error', console.error)
tgclient.on('update', update => {
console.log('Received update:', update)
})
async function main () {
await tgclient.connectAndLogin()
console.log(await tgclient.invoke({ _: 'getMe' }))
// ...
}
main().catch(console.error)
module.exports = tgclient
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment