Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Volodymyr Saakian committed Mar 3, 2020
1 parent 9d6d261 commit 5a9cf02
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 39 deletions.
30 changes: 30 additions & 0 deletions ecosystem.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module.exports = {
apps: [
{
name: 'Exchange bot',
script: './src/index.js',
instances: 1,
autorestart: true,
watch: true,
max_memory_restart: '200M',
env: {
NODE_ENV: 'development'
},
env_production: {
NODE_ENV: 'production'
}
}
],

deploy: {
production: {
user: 'node',
host: '212.83.163.1',
ref: 'origin/master',
repo: 'git@github.com:repo.git',
path: '/var/www/production',
'post-deploy':
'npm install && pm2 reload ecosystem.config.js --env production'
}
}
};
8 changes: 2 additions & 6 deletions src/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ const FinanceApi = require('./utils/api/FinanceApi');
//978534005 bot
class TelegramExecutor extends DynamoDatabase {
async execute() {
console.log('Starting');
console.log(TOKEN);
const bot = new Telegraf(TOKEN);
const telegram = new Telegram(TOKEN);
console.log(await telegram.getChatMembersCount(978534005));
// await telegram.sendMessage(251408559, 'Hello');
// console.log(await this.putItem());

bot.start(async ctx => {
console.log(ctx);
ctx.telegram.setChatPermissions(ctx.botInfo.id, {
Expand Down Expand Up @@ -57,7 +54,6 @@ class TelegramExecutor extends DynamoDatabase {
// return ctx.telegram.sendMessage(251408559, template);
return ctx.reply(template);
});
// console.log(bot.getMe());
bot.command('showratesfinance', ctx => {
console.log(123123);
return ctx.reply('Hello');
Expand Down
10 changes: 0 additions & 10 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,6 @@ const AWS = require('aws-sdk');
const TelegramExecutor = require('./bot');

(async () => {
// console.log(
// await got
// .get("http://resources.finance.ua/ru/public/currency-cash.json")
// .json()
// );
console.log(123);
const botInstance = new TelegramExecutor();
console.log(await botInstance.listTables());
await botInstance.execute();
// console.log(listTables);
})();
// var credentials = new AWS.SharedIniFileCredentials({ profile: "work-account" });
// AWS.config.credentials = credentials;
43 changes: 20 additions & 23 deletions src/utils/aws/dynamo.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const got = require('got');
const AWS = require('aws-sdk');

const tableName = 'exchane-rates-ukraine-bot';
class DynamoDatabase {
constructor() {
this.dynamodb = new AWS.DynamoDB({
Expand All @@ -12,52 +12,49 @@ class DynamoDatabase {
return this.dynamodb.listTables({}).promise();
}

async listTables() {
return this.dynamodb.listTables({}).promise();
}
async putItem({ tableName }) {
async getItem() {
var params = {
TableName: tableName,
Item: {
CUSTOMER_ID: { N: '001' },
CUSTOMER_NAME: { S: 'Richard Roe' }
}
Key: {
123: {}
},
ProjectionExpression: 'integer'
};

ddb.putItem(params, function(err, data) {
this.dynamodb.getItem(params, function(err, data) {
if (err) {
console.log('Error', err);
} else {
console.log('Success', data);
console.log('Success', data.Item);
}
});
}

async getItem() {
async putItem() {
var params = {
TableName: 'TABLE',
Key: {
KEY_NAME: { N: '001' }
},
ProjectionExpression: 'ATTRIBUTE_NAME'
TableName: tableName,
Item: {
CUSTOMER_ID: { N: '001' },
CUSTOMER_NAME: { S: 'Richard Roe' }
}
};
ddb.getItem(params, function(err, data) {

this.dynamodb.putItem(params, function(err, data) {
if (err) {
console.log('Error', err);
} else {
console.log('Success', data.Item);
console.log('Success', data);
}
});
}

async deleteItem() {
var params = {
TableName: 'TABLE',
TableName: tableName,
Key: {
KEY_NAME: { N: 'VALUE' }
}
};
ddb.deleteItem(params, function(err, data) {
this.dynamodb.deleteItem(params, function(err, data) {
if (err) {
console.log('Error', err);
} else {
Expand All @@ -79,7 +76,7 @@ class DynamoDatabase {
}
};

ddb.batchGetItem(params, function(err, data) {
this.dynamodb.batchGetItem(params, function(err, data) {
if (err) {
console.log('Error', err);
} else {
Expand Down

0 comments on commit 5a9cf02

Please sign in to comment.