Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Details

Privacy

Go PRO Window blinds lowered to protect code. Code Editor with window blinds (raised) and a light blub turned on.

Keep it secret; keep it safe.

Private Pens are hidden everywhere on CodePen, except to you. You can still share them and other people can see them, they just can't find them through searching or browsing.

Upgrade to PRO

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

Template

Make Template?

Templates are Pens that can be used to start other Pens quickly from the create menu. The new Pen will copy all the code and settings from the template and make a new Pen (that is not a fork). You can view all of your templates, or learn more in the documentation.

Template URL

Any Pen can act as a template (even if you don't flip the toggle above) with a special URL you can use yourself or share with others. Here's this Pen's template URL:

Screenshot

Screenshot or Custom Thumbnail

Screenshots of Pens are shown in mobile browsers, RSS feeds, to users who chose images instead of iframes, and in social media sharing.

This Pen is using the default Screenshot, generated by CodePen. Upgrade to PRO to upload your own thumbnail that will be displayed on previews of this pen throughout the site and when sharing to social media.

Upgrade to PRO

HTML

              
                
              
            
!

CSS

              
                
              
            
!

JS

              
                function telegram(method, params) {
	var token = "ТОКЕН БОТА ТАЛЕГРАМ";
	var url = "https://api.telegram.org/bot" + token + "/" + method;
	return UrlFetchApp.fetch(url, {
		'method': 'post',
		'payload': params
	});
}

function setWebHook() {
	var resp = telegram("setWebhook", {
		"url": "ССЫЛКА СОЗДАННАЯ ЧЕРЕЗ Развертывание как веб-приложения в редакторе скриптов"
	});
	Logger.log(resp);
}


function onOpen() {
	var ui = SpreadsheetApp.getUi();
	ui.createMenu('Telegram')
		.addItem('Уведомдение', 'sendNotify')
		.addToUi();
}

function getChatMessages (type) {
//  if (type == 'array') return [60168975]
//  if (type == 'object') return ['60168975']

  if (type == 'array') return [60168975, 263324337]
  if (type == 'object') return ['60168975', '263324337']
}

function getInlineKeyboard (ss) {
  return JSON.stringify({
				'inline_keyboard': [
					[{
						text: 'Открыть таблицу',
						url: url = "https://docs.google.com/spreadsheets/d/" + ss.getId()
					}]
				],
				'resize_keyboard': true,
				'one_time_keyboard': true
			})
}


function sendNotifyEvening () {
	var chatList = getChatMessages('object');
	var ss = SpreadsheetApp.getActiveSpreadsheet();

	for (var i = 0; i < chatList.length; i++) {
		telegram('sendMessage', {
			'chat_id': chatList[i],
			'parse_mode': 'HTML',
			'text': getData('today'),
			'reply_markup': getInlineKeyboard(ss)
		});
	}
}

function sendNotify () {
	var chatList = getChatMessages('object');
	var ss = SpreadsheetApp.getActiveSpreadsheet();

	for (var i = 0; i < chatList.length; i++) {
		telegram('sendMessage', {
			'chat_id': chatList[i],
			'parse_mode': 'HTML',
			'text': getData('moring'),
			'reply_markup': getInlineKeyboard(ss)
		});
	}
}

function getData(flow) {
	eval(UrlFetchApp.fetch('https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment-with-locales.js').getContentText());
	moment.locale('ru');

	var date = moment().format('dddd, D MMMM')

	var ss = SpreadsheetApp.getActiveSpreadsheet();
	var sheet = ss.getSheetByName(moment().format('MMMM'));

	var url = "https://docs.google.com/spreadsheets/d/" + ss.getId();

	var moneyFromToday = sheet.getRange("B29").getDisplayValue();

    var todayMoneyIcon = (sheet.getRange("B29").getDisplayValue() <= 500) ? ((sheet.getRange("B29").getDisplayValue() <= 0) ? '🆘' : '⛔') : '✅'
	var tomorrowMoneyIcon = (sheet.getRange("B30").getDisplayValue() <= 500) ? ((sheet.getRange("B30").getDisplayValue() <= 0) ? '🆘' : '⛔') : '✅'
    
    var todayPayedMoney = (sheet.getRange("B26").getDisplayValue() == "") ? '0, 00' : sheet.getRange("B26").getDisplayValue()
    var todayPayedList = (sheet.getRange("B27").getDisplayValue() == "") ? '---' : sheet.getRange("B27").getDisplayValue()

	var text = '📢 Сегодня: <b>' + moment(sheet.getRange("B25").getDisplayValue()).format('dddd, D MMMM') + '</b>\n';
	text += '—————————\n';
    text += 'Потрачено за сегодня: <b>' + todayPayedMoney + '</b> руб.\n';
	text += 'На что потрачено:  <code>' + todayPayedList  + '</code>\n';
	text += '—————————\n';
	text += todayMoneyIcon + ' Осталось на сегодня: <b>' + sheet.getRange("B29").getDisplayValue() + '</b> руб.\n';
	text += tomorrowMoneyIcon + ' Осталось на зватра: <b>' + sheet.getRange("B30").getDisplayValue() + '</b> руб.\n';
	text += '—————————\n';
	text += '💶 Осталось в этом месяце: <b>' + sheet.getRange("B31").getDisplayValue() + '</b> руб.\n'
	text += '🏦 Потрачено в этом месяце: <b>' + sheet.getRange("I33").getDisplayValue() + '</b> руб.'

	var everyDayNotify = todayMoneyIcon + ' Бюджет на сегодя <b>' + date + '</b>: <b>' + moneyFromToday + '</b> руб.'

	if (flow === 'today') return text
	if (flow === 'moring') return everyDayNotify
}

function writeData(price, description, msg) {
	if (!price || !description) {
		telegram('sendMessage', {
			'chat_id': msg.message.chat.id,
			'text': '😥 Всё не то. Давай по новой..'
		});
		return false;
	}

	eval(UrlFetchApp.fetch('https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment-with-locales.js').getContentText());
	moment.locale('ru');

	var ss = SpreadsheetApp.getActiveSpreadsheet();
	var sheet = ss.getSheetByName(moment().format('MMMM'));

	var currentDateDay = new Date().getDate();
	var startDateDay = new Date(sheet.getRange("B1").getDisplayValue()).getDate()

	var currentDayRow = (currentDateDay - startDateDay) + 2

	var currentValue = sheet.getRange(currentDayRow, 9).getFormula()
	var currentDescription = sheet.getRange(currentDayRow, 8).getValue()
	var newValue


	if (price[0] == '=') {
		newValue = price;
	} else {
		var symb = (price[0] == '-') ? '' : '+';
		newValue = ((currentValue == "") ? "=" : (currentValue + symb)) + price.split(' ')[0];
	}

	var newDescription = ((currentDescription == "") ? description : currentDescription + ', ' + description)

	// Записываем занные в соответствующие ячейки
	sheet.getRange(currentDayRow, 9).setFormula(newValue)
	sheet.getRange(currentDayRow, 8).setValue(newDescription)
    
    return true
}

function doPost(e) {
	// можно вписать несколько номеров. Например
	//var chatList = [123456789, 987654321];
	// тут номера обязательно без кавычек
	var chatList = getChatMessages('array');

	var ss = SpreadsheetApp.getActiveSpreadsheet();
	var url = "https://docs.google.com/spreadsheets/d/" + ss.getId();

	var msg = JSON.parse(e.postData.contents);

	if (chatList.indexOf(msg.message.chat.id) == -1) {
		telegram('sendMessage', {
			'chat_id': msg.message.chat.id,
			'text': msg.message.chat.id
		});
		return;
	}

	// ################################# Telegram command part #################################
	var isCmd = false;
	if (msg.message.entities != undefined) {
		for (var i = 0; i < msg.message.entities.length; i++) {
			if (msg.message.entities[i].type == "bot_command") {
				var cmd = msg.message.text.replace('/', '');

				if (cmd == 'chat') {
					telegram('sendMessage', {
						'chat_id': msg.message.chat.id,
						'text': 'Chat id: ' + msg.message.chat.id
					});
				} else if (cmd == "info") {

					telegram('sendMessage', {
						'chat_id': msg.message.chat.id,
						'parse_mode': 'HTML',
						'text': getData('today'),
						'reply_markup': getInlineKeyboard(ss)
					});
				} else if (cmd == "start") {
					telegram('sendMessage', {
						'chat_id': msg.message.chat.id,
						'text': 'Ну привет 😎'
					});
				} else {
					telegram('sendMessage', {
						'chat_id': msg.message.chat.id,
						'text': 'Всё не то. Давай по новой..'
					});
				}

				isCmd = true;
			}
		}
	}
	if (isCmd == true) return;
	// ################################# Telegram command part end #################################


	var price = msg.message.text.split(";")[0]
	var description = msg.message.text.split(";")[1]

	var isSuccess = writeData(price, description, msg)
    if (!isSuccess) return;

	for (var i = 0; i < chatList.length; i++) {
		if (chatList[i] == msg.message.chat.id) {
			telegram('sendMessage', {
				'chat_id': '' + chatList[i],
				'text': getOkMessage(),
				'reply_markup': getInlineKeyboard(ss)
			});
		}
	}
}


function getOkMessage() {
	ok_messages = [
		"👍 Угу",
		"🤟 Исполнено",
		"😴 Добавил",
		"🙊 Оке",
		"✔️ Done",
		"🧐 Как скажешь",
		"🙄 Ну ок",
		"💩 Ага",
		"🤔 Хорошо",
		"😆 Ок"
	];
	var index = (Math.random() * 10) | 0;
	return ok_messages[index];
}
              
            
!
999px
How do you comfort a JavaScript bug? You console it!

Console