This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npm init --force | |
npm install typescript --global | |
npm install typescript --save-dev | |
tsc --init |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npm install telegraf dotenv itunes-search @types/node @types/dotenv --save-dev |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
node_modules | |
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BOT_KEY="SuaChaveQueOTelegramDeuAqui" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
... | |
"main": "node dist/main.js", | |
"scripts": { | |
"start": "node dist/main.js", | |
"build": "tsc", | |
"watch": "tsc -w" | |
}, | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
"compilerOptions": { | |
"target": "es6", | |
"module": "commonjs", | |
... | |
"outDir": "dist", | |
... | |
"moduleResolution": "node", | |
"typeRoots": [ | |
"node_modules" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* main.ts, programa principal. | |
*/ | |
'use strict'; | |
import { config } from 'dotenv'; | |
import * as telegraf from 'telegraf'; | |
// Irá inicializar e procurar o arquivo .env e carregar suas chaves e valores. | |
config(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bot.command('search', ({ replyWithMarkdown, message }) => { | |
// Irá remover o '/search' da pequisa e retornar apenas o nome da podcast. | |
const nome: string = message.text.replace(/(\/\w+)\s*/, ''); | |
// Parametros para a pesquisa na iTunes, aqui que você deve mudar caso queira fazer deste um bot de música ou de filmes. | |
const opcoes: object = { | |
media: 'podcast', | |
entity: 'podcast', | |
limit: 1 | |
}; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bot.on('inline_query', ({ answerInlineQuery, inlineQuery }) => { | |
const nome: string = inlineQuery.query; | |
// Quantidade máxima de podcasts a serem pequisados para serem retornados por pesquisa. | |
const limitePesquisa: number = 20; | |
// Offset é a "página" que o usário se encontra no scroll das pequisas inline. | |
const offset: number = parseInt(inlineQuery.offset, 10) || 0; | |
const opcoes: object = { | |
media: 'podcast', | |
entity: 'podcast', | |
limit: offset + limitePesquisa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npm install jest ts-jest @types/jest request --save-dev |
OlderNewer