import config from "./config_local.js";
class TgApp {
constructor(containerId, userId) {
this.container = document.getElementById(containerId);
this.userId = userId;
}
actionMain(){
console.log("main 123")
this.createCardBox();
this.createDefaultBox();
this.getCard();
}
setUserId(userId) {
this.userId = userId;
}
createCardBox() {
this.cardBox = document.createElement("div");
this.cardBox.setAttribute("id", "cardBox");
this.cardBox.innerHTML = templates.preloader();
this.container.appendChild(this.cardBox);
}
createDefaultBox() {
this.defaultBox = document.createElement("div");
this.defaultBox.setAttribute("id", "defaultBox");
this.defaultBox.innerHTML = templates.defaultBox();
this.container.appendChild(this.defaultBox);
}
getCard() {
let botId = config.config.botId;
fetch(config.config.apiUrl + `api/tg-bot/get-card-by-dialog/${this.userId}/${botId}`, {
method: 'GET', // Здесь так же могут быть GET, PUT, DELETE
headers: {
// Добавляем необходимые заголовки
'Content-type': 'application/json; charset=UTF-8',
},
})
.then((response) => response.json())
.then((data) => {
this.cardBox.innerHTML = templates.cardBox(data.card_file.file, data.balance)
// {title: "foo", body: "bar", userId: 1, id: 101}
})
}
getAction(action){
if (action === "actionMain"){
return this.actionMain;
}
return false;
}
}
const templates =
{
preloader: () => {
return '';
},
defaultBox: () => {
return `
Акция на Старый Новый Год Акция на Старый Новый Год Акция на Старый Новый Год Акция на Старый Новый Год
Принять участие