Full Code of tegohsx/laporan-keuangan-bot for AI

main 7ecc571e0db9 cached
2 files
9.7 KB
3.0k tokens
1 requests
Download .txt
Repository: tegohsx/laporan-keuangan-bot
Branch: main
Commit: 7ecc571e0db9
Files: 2
Total size: 9.7 KB

Directory structure:
gitextract_qm0c1jqc/

├── Kode.gs
└── README.md

================================================
FILE CONTENTS
================================================

================================================
FILE: Kode.gs
================================================
//CONFIG
var BOT_TOKEN = "6642440655:AADRAWN3nXcuJf5xJkSQLhyJgQXGag08cLc" //BOT TOKEN ANDA
var SS_URL = "https://docs.google.com/spreadsheets/d/1LArhvsBXZ8lJ3tzvx8DyYrFWwtRxlQsWQEFzdsyignw/edit#gid=0" //URL SPREADSHEET
var CREDIT_SHEET_NAME = "Pemasukan" //NAMA SHEET PEMASUKAN
var DEBIT_SHEET_NAME = "Pengeluaran" //NAMA SHEET PENGELUARAN


//BEGIN
const ss = SpreadsheetApp.openByUrl(SS_URL);
const creditSheet = ss.getSheetByName(CREDIT_SHEET_NAME);
const debitSheet = ss.getSheetByName(DEBIT_SHEET_NAME);
const Credit = new Collection.Collect(creditSheet)
const Debit = new Collection.Collect(debitSheet)

function doGet(e) {
  return HtmlService.createHtmlOutput('<h1>OK</h1>')
}

function doPost(e) {
  const queryParameters = e.parameter;
  const usersQuery = queryParameters.users
  const validUsers = usersQuery.split(',')
  try {
    if (e.postData.type == "application/json") {
      let update = JSON.parse(e.postData.contents);
      if (update) {
        commands(update, validUsers)
        return true
      }
    }
  } catch (e) {
    Logger.log(e)
  }
}

function commands(update, validUsers) {

  const chatId = update.message.chat.id;
  const first_name = update.message.chat.first_name;
  const text = update.message.text || '';
  const tanggal = new Date().toLocaleString();
  const _date = new Date().toJSON()

  if (validUsers.includes(String(chatId))) {

    if (text.startsWith("/start")) {
      sendMessage({
        chat_id: chatId,
        text: "Mulai laporan keuangan.\nPemasukan:\n/masuk [nominal] [#kategori] [item1, item2 dst]\nPengeluaran:\n/keluar [nominal] [#kategori] [item1, item2 dst]\n\nRekapitulasi: /rekap [tanggal/bulan] [tanggal/bulan (opsional)]\nTanggal dan bulan berformat YYYY-MM-DD dan YYYY-MM\nContoh: \n/rekap 2024-01-01\n/rekap 2024-01-01 2024-01-10\n/rekap 2024-01\n/rekap 2024-01 2024-06"
      })
    } else if (text.startsWith("/masuk")) {
      const stext = text.split(' ')

      const nominal = Number(stext[1]);
      const kategori = stext[2].startsWith('#') ? stext[2].replace('#', '') : '';

      stext.splice(0, 3);
      const item = stext.join(' ')

      if (nominal && kategori && item) {

        Credit.insert(
          {
            _date,
            Tanggal: tanggal,
            Kategori: kategori,
            Nominal: nominal,
            Item: item,
            ReporterID: chatId,
            ReporterName: first_name
          }
        )

        sendMessage({
          chat_id: chatId,
          text: 'Laporan pemasukan sukses.'
        })

      } else {
        sendMessage({
          chat_id: chatId,
          text: 'Gagal. Pastikan sesuai format. \n/masuk [harga] [#kategori] [item1, item2 dst]'
        })
      }
    } else if (text.startsWith("/keluar")) {
      const stext = text.split(' ')

      const nominal = Number(stext[1]);
      const kategori = stext[2].startsWith('#') ? stext[2].replace('#', '') : '';

      stext.splice(0, 3);
      const item = stext.join(' ')

      if (nominal && kategori && item) {

        Debit.insert(
          {
            _date,
            Tanggal: tanggal,
            Kategori: kategori,
            Nominal: nominal,
            Item: item,
            ReporterID: chatId,
            ReporterName: first_name
          }
        )

        sendMessage({
          chat_id: chatId,
          text: 'Laporan pengeluaran sukses.'
        })

      } else {
        sendMessage({
          chat_id: chatId,
          text: 'Gagal. Pastikan sesuai format. \n/keluar [harga] [#kategori] [item1, item2 dst]'
        })
      }
    } else if (text.startsWith("/rekap")) {
      const stext = text.split(' ')
      stext.splice(0, 1);

      const oDateRange = Collection.generateDateRange(stext.join(' '))
      const dataRange = oDateRange.dateRange
      const sumType = oDateRange.sumType
      const monthNames = ['Januari', 'Februari', 'Maret', 'April', 'Mei', 'Juni', 'Juli', 'Agustus', 'September', 'Oktober', 'November', 'Desember']

      if (dataRange.length > 0) {
        let textToSend = "Rekapitulasi: \n"

        for (let _date of dataRange) {
          const pengeluaran = Debit.find(
            {
              _date: d => new Date(d) >= _date.from && new Date(d) < _date.to
            }
          )

          const pemasukan = Credit.find(
            {
              _date: d => new Date(d) >= _date.from && new Date(d) < _date.to
            }
          )

          let rekapMasuk = pemasukan.reduce((acc, item) => {
            if (!acc[item.Kategori]) {
              acc[item.Kategori] = 0;
            }
            acc[item.Kategori] += item.Nominal;
            return acc;
          }, {});

          let rekapKeluar = pengeluaran.reduce((acc, item) => {
            if (!acc[item.Kategori]) {
              acc[item.Kategori] = 0;
            }
            acc[item.Kategori] += item.Nominal;
            return acc;
          }, {});

          if (sumType == 'daily') {
            let dateTo = new Date(_date.to)
            dateTo.setDate(dateTo.getDate() - 1)
            textToSend += "Pemasukan " + _date.from.toLocaleDateString() + ' s.d ' + dateTo.toLocaleDateString() + "\n"
            textToSend += Object.keys(rekapMasuk).map((i) => `${i}: ${Number(rekapMasuk[i]).toLocaleString('id-ID')}`).join('\n') || '---'
            textToSend += '\nTotal: ' + Object.values(rekapMasuk).reduce((acc, value) => acc + value, 0).toLocaleString('id-ID');
            textToSend += "\n"
            textToSend += "\n"
            textToSend += "Pengeluaran " + _date.from.toLocaleDateString() + ' s.d ' + dateTo.toLocaleDateString() + "\n"
            textToSend += Object.keys(rekapKeluar).map((i) => `${i}: ${Number(rekapKeluar[i]).toLocaleString('id-ID')}`).join('\n') || '---'
            textToSend += '\nTotal: ' + Object.values(rekapKeluar).reduce((acc, value) => acc + value, 0).toLocaleString('id-ID');
            textToSend += "\n"
            textToSend += "\n"

          }
          else {
            textToSend += "Pemasukan bulan " + monthNames[_date.from.getMonth()] + ' ' + _date.from.getFullYear() + "\n"

            textToSend += Object.keys(rekapMasuk).map((i) => `${i}: ${Number(rekapMasuk[i]).toLocaleString('id-ID')}`).join('\n') || '---'
            textToSend += '\nTotal: ' + Object.values(rekapMasuk).reduce((acc, value) => acc + value, 0).toLocaleString('id-ID');
            textToSend += "\n"

            textToSend += "\n"

            textToSend += "Pengeluaran bulan " + monthNames[_date.from.getMonth()] + ' ' + _date.from.getFullYear() + "\n"

            textToSend += Object.keys(rekapKeluar).map((i) => `${i}: ${Number(rekapKeluar[i]).toLocaleString('id-ID')}`).join('\n') || '---'
            textToSend += '\nTotal: ' + Object.values(rekapKeluar).reduce((acc, value) => acc + value, 0).toLocaleString('id-ID');
            textToSend += "\n"

            textToSend += "\n"
          }
        }

        sendMessage({
          chat_id: chatId,
          text: textToSend
        })

      } else {
        sendMessage({
          chat_id: chatId,
          text: 'Gagal. Pastikan sesuai format. \n/rekap [tanggal/bulan] [tanggal/bulan (opsional)]\nTanggal dan bulan berformat YYYY-MM-DD dan YYYY-MM\nContoh: \n/rekap 2024-01-01\n/rekap 2024-01-01 2024-01-10\n/rekap 2024-01\n/rekap 2024-01 2024-06'
        })
      }
    }
  }
}

function sendMessage(postdata) {
  var options = {
    'method': 'post',
    'contentType': 'application/json',
    'payload': JSON.stringify(postdata),
    'muteHttpExceptions': true
  };
  UrlFetchApp.fetch('https://api.telegram.org/bot' + BOT_TOKEN + '/sendMessage', options);
}


================================================
FILE: README.md
================================================
# laporan-keuangan-bot
[![Version](https://img.shields.io/badge/Version-2.0.1-green)]()
[![Beta](https://img.shields.io/badge/Beta-orange)]()<br>
Laporan keuangan, pencataan pemasukan dan pengeluaran dengan Bot Telegram yang terintegrasi dengan Google Spreadsheet

### Video Tutorial
https://youtu.be/sII577Ubv-E

<br>
<img src="https://github.com/tegohsx/laporan-keuangan-bot/assets/101353193/d8aaafe8-62f6-45a0-bf8c-7934f61c7d3b" width="50%">


### Yang ada di bot
1. Input pemasukan: <code>/masuk [nominal] [#kategori] [item1, item2, keterangan dsb.]</code> <br>
   Contoh:  <br>
      /masuk 100000 #gaji angkut barang <br>
2. Input pengeluaran: <code>/keluar [nominal] [#kategori] [item1, item2, keterangan dsb.]</code> <br>
   Contoh:  <br>
      /keluar 50000 #makan roti dan kopi <br>
3. Rekapitulasi: <code>/rekap [tanggal/bulan] [tanggal/bulan (opsional)]</code> <br>
   Tanggal dan bulan berformat YYYY-MM-DD dan YYYY-MM <br>
   Contoh: <br>
      /rekap 2024-02-01<br>
      /rekap 2024-02-01 2024-02-10<br>
      /rekap 2024-02<br>
      /rekap 2024-02 2024-06<br>


# Mulai

## Buat Bot telegram
1. Buka telegram search @BotFather
2. Create New Bot /newbot
3. Masukkan nama kemudian username.
4. Setelah berhasil maka akan mendapatkan Bot Token.

## Buat Spreadsheet
Buat dua sheet untuk pemasukan dan pengeluaran dengan kolom:
1. _id
2. _date
3. Tanggal
4. Kategori
5. Item
6. Nominal
7. ReporterID
8. ReporterName

## Buat Apps Script
1. Copy Kode.gs
2. Sesuaikan Token, Spreadsheet URL, dan Nama Sheet untuk pemasukan dan pengeluaran
3. Tambahkan Library dengan ID: <code>1CZD-ai-ImkabBPSBVOqnFFWlXoA5kUEfoXvUXOC3uQHr_qpF1H7amHMr</code>
4. Deploy sebagai Web app, dan simpan URL-nya

## Set webhook Bot Telegram
1. Buka di browser <code>https[]()://api.telegram.org/bot[token]/setwebhook?url=[url hasil deploy]?users=ChatID1,ChatID2,...</code><br>
Sesuaikan ChatID* dengan user yang akan menggunakan bot, bisa lebih dari satu, pisahkan dengan koma.

## *Note:
Untuk mendapatkan Chat ID, buka telegram, search <code>@getYourID_bot</code> atau https://t.me/getyourid_bot


## Contact
Telegram: https://t.me/mastgh <br>
WhatsApp: +62 855-1000-113

## Donasi
Paypal tegohsx@gmail.com <br>
BRI 000401061441500 <br>
Jago 100310049829 <br>
DANA/GOPAY 085290465350 <br>
a/n Teguh S
Download .txt
gitextract_qm0c1jqc/

├── Kode.gs
└── README.md
Condensed preview — 2 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (10K chars).
[
  {
    "path": "Kode.gs",
    "chars": 7630,
    "preview": "//CONFIG\nvar BOT_TOKEN = \"6642440655:AADRAWN3nXcuJf5xJkSQLhyJgQXGag08cLc\" //BOT TOKEN ANDA\nvar SS_URL = \"https://docs.go"
  },
  {
    "path": "README.md",
    "chars": 2291,
    "preview": "# laporan-keuangan-bot\n[![Version](https://img.shields.io/badge/Version-2.0.1-green)]()\n[![Beta](https://img.shields.io/"
  }
]

About this extraction

This page contains the full source code of the tegohsx/laporan-keuangan-bot GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 2 files (9.7 KB), approximately 3.0k tokens. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!