Skip to content

Commit

Permalink
Telegram poll api
Browse files Browse the repository at this point in the history
  • Loading branch information
RybakV committed Jan 24, 2024
1 parent 804ffdb commit b77137d
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 70 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ <h1>Coin</h1>
<br/>
<a href="https://rybakv.github.io/pages/on-power-off/">JS: On-Power-Off schedule</a>
<br/>
<a href="https://rybakv.github.io/pages/twitter-poll-api/">JS: Twitter poll api</a>
<a href="https://rybakv.github.io/pages/telegram-poll-api/">JS: Telegram poll api</a>
<br/>

<!--a href="https://rc-portal-game-1.vercel.app/">Game: Portal Hamster</a-->
Expand Down
20 changes: 13 additions & 7 deletions twitter-poll-api/css/style.css → telegram-poll-api/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,27 @@
}
body {
font-family: Arial, sans-serif;
background-color: #1f2431;
color: #90a1b9;
background-color: #0d496f;
color: #ffbf6b;
padding: 40px;
font-size: 20px;
}
.container {
max-width: 1000px;
margin: 0 auto;
display: flex;
gap: 24px;
flex-direction: column;
}
#result {
background-color: #1b1b1b;
border: 2px solid #41454f;
background-color: #647176;
border-radius: 4px;
padding: 24px;
}
.btn {
border: 2px solid #dd8822;
background-color: #ff9f2f;
color: #fff;
border: 2px solid #647176;
background-color: #ffbf6b;
color: #0d496f;
padding: 10px 20px;
border-radius: 4px;
font-size: 20px;
Expand Down
Binary file added telegram-poll-api/favicon.ico
Binary file not shown.
23 changes: 10 additions & 13 deletions twitter-poll-api/index.html → telegram-poll-api/index.html
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
<!DOCTYPE html>
<html lang="en">
<head>
<link rel='icon' href='favicon.ico' type='image/x-icon'/ >
<title>Telegram poll api</title>
<link rel='icon' href='favicon.ico' type='image/x-icon' />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="author" content="RybakV" />
<meta name="description" content="Twitter poll api fetching votes">
<meta name="keywords" content="Rybak, JS, Twitter, API">
<meta name="description" content="Telegram poll api fetching votes">
<meta name="keywords" content="Rybak, JS, Telegram, API">

<!-- OG image for nice social networks sharing -->
<meta property="og:title" content="Twitter poll api">
<meta property="og:description" content="Twitter poll api fetching votes">
<meta property="og:title" content="Telegram poll api">
<meta property="og:description" content="Telegram poll api fetching votes">
<!--<meta property="og:image" content="http://rybak.github.io/img/coin.gif">-->
<meta property="og:url" content="http://rybak.github.io/">

<meta name="twitter:title" content="Twitter poll api">
<meta name="twitter:description" content="Twitter poll api fetching votes">
<meta name="twitter:title" content="Telegram poll api">
<meta name="twitter:description" content="Telegram poll api fetching votes">
<!--<meta name="twitter:image" content="http://rybak.github.io/img/coin.gif">-->
<!--<meta name="twitter:card" content="summary_large_image">-->

<!-- Document title -->
<title>Twitter poll api</title>
<!-- Stylesheets & Fonts -->
<link href="./css/style.css" rel="stylesheet">

<body>
<div class="container text-center">
<h1>Twitter(X) votes API</h1>
<div class="container">
<h1>Telegram votes API</h1>
<button class="btn" id="start">Start</button>
<div id="result"></div>
</div>
Expand Down
40 changes: 40 additions & 0 deletions telegram-poll-api/js/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const startBtn = document.querySelector('#start');
const resultBox = document.querySelector('#result');
startBtn.addEventListener('click', startApp);

const token = '6984190497:AAFivyswRSE2zT8bK_AL7RYf_znndhov7tA';
const firstPost = '800520411' // update_id of the first post
const postsQuantity = '1'

function startApp(){
// fetch(`https://api.telegram.org/bot${token}/getUpdates?offset=${firstPost}&limit=${postsQuantity}`)
fetch(`https://api.telegram.org/bot${token}/getUpdates`)
.then((response) => response.json())
.then((data) => {
console.log('Fetch data:',data);
console.log('Fetch data:',data.result[0].message.poll);
renderPoll(data.result[0].message.poll);
})
}

async function renderPoll(pollData){
const newPoll = document.createElement('div');
newPoll.classList.add('poll');
const pollTitle = createHtmlNode('h1', pollData.question);
newPoll.appendChild(pollTitle);
resultBox.appendChild(newPoll);


const pollOptions = document.createElement('ul');
pollData.options.map((option) => {
const optionNode = createHtmlNode('li', `${option.text}: ${option.voter_count}`)
pollOptions.appendChild(optionNode);
});
resultBox.appendChild(pollOptions);
}

function createHtmlNode(tag, content){
const node = document.createElement(tag);
node.innerText = content;
return node;
}
49 changes: 0 additions & 49 deletions twitter-poll-api/js/script.js

This file was deleted.

0 comments on commit b77137d

Please sign in to comment.