Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// code by Negezor (https://github.com/negezor)
let { Telegram } = require('puregram');
let { SessionManager } = require('@puregram/session');
let { SceneManager, StepScene } = require('@puregram/scenes');
let telegram = new Telegram({
token: process.env.TOKEN,
});
let sessionManager = new SessionManager();
let sceneManager = new SceneManager();
sceneManager.addScene(
new StepScene('signup', [
(context) => {
if (context.scene.step.firstTime || !context.text) {
return context.send('What\'s your name?');
}
context.scene.state.firstName = context.text;
return context.scene.step.next();
telegram.updates.hear('/keyboard', (context) => {
return context.send('There\'s your keyboard!', {
reply_markup: Keyboard.keyboard([
[
Keyboard.textButton('Button'),
],
[
Keyboard.textButton('Another button'),
Keyboard.textButton('But there\'s more!'),
],
[
Keyboard.textButton('So'),
Keyboard.textButton('many'),
Keyboard.textButton('buttons!'),
],
]).resize(),
});
});
telegram.updates.hear('/keyboard', (context) => {
return context.send('There\'s your keyboard!', {
reply_markup: Keyboard.keyboard([
[
Keyboard.textButton('Button'),
],
[
Keyboard.textButton('Another button'),
Keyboard.textButton('But there\'s more!'),
],
[
Keyboard.textButton('So'),
Keyboard.textButton('many'),
Keyboard.textButton('buttons!'),
],
]).resize(),
});
});
telegram.updates.hear('/keyboard', (context) => {
return context.send('There\'s your keyboard!', {
reply_markup: Keyboard.keyboard([
[
Keyboard.textButton('Button'),
],
[
Keyboard.textButton('Another button'),
Keyboard.textButton('But there\'s more!'),
],
[
Keyboard.textButton('So'),
Keyboard.textButton('many'),
Keyboard.textButton('buttons!'),
],
]).resize(),
});
});
telegram.updates.hear('/keyboard', (context) => {
return context.send('There\'s your keyboard!', {
reply_markup: Keyboard.keyboard([
[
Keyboard.textButton('Button'),
],
[
Keyboard.textButton('Another button'),
Keyboard.textButton('But there\'s more!'),
],
[
Keyboard.textButton('So'),
Keyboard.textButton('many'),
Keyboard.textButton('buttons!'),
],
]).resize(),
});
});
telegram.updates.hear('/keyboard', (context) => {
return context.send('There\'s your keyboard!', {
reply_markup: Keyboard.keyboard([
[
Keyboard.textButton('Button'),
],
[
Keyboard.textButton('Another button'),
Keyboard.textButton('But there\'s more!'),
],
[
Keyboard.textButton('So'),
Keyboard.textButton('many'),
Keyboard.textButton('buttons!'),
],
]).resize(),
});
});
telegram.updates.hear('/keyboard', (context) => {
return context.send('There\'s your keyboard!', {
reply_markup: Keyboard.keyboard([
[
Keyboard.textButton('Button'),
],
[
Keyboard.textButton('Another button'),
Keyboard.textButton('But there\'s more!'),
],
[
Keyboard.textButton('So'),
Keyboard.textButton('many'),
Keyboard.textButton('buttons!'),
],
]).resize(),
});
});
let { oneLine } = require('common-tags');
let { Telegram, HTML, Markdown } = require('puregram');
let telegram = new Telegram({
token: process.env.TOKEN,
});
telegram.updates.hear(/^markdown$/i, (context) => {
return context.send(
oneLine`
Some ${Markdown.bold('epic')} ${Markdown.italic('markdown')}
${Markdown.code('right')} ${Markdown.url('there', 'example.com')}!
`,
{
/**
* There are 3 ways to pass Markdown or HTML as a parameter.
*
* First is to pass class into parse_mode.
*/
parse_mode: Markdown,
let {
Telegram,
Keyboard,
KeyboardBuilder,
InlineKeyboard,
InlineKeyboardBuilder,
} = require('puregram');
let telegram = new Telegram({
token: process.env.TOKEN,
});
telegram.updates.setHearFallbackHandler(
context => context.send(
'Enter either /keyboard, /keyboardbuilder, /inline or /inlinebuilder.',
),
);
telegram.updates.hear('/keyboard', (context) => {
return context.send('There\'s your keyboard!', {
reply_markup: Keyboard.keyboard([
[
Keyboard.textButton('Button'),
],
let { Telegram } = require('puregram');
let telegram = new Telegram({
token: process.env.TOKEN,
});
telegram.updates.hear(
/^hello/i,
context => context.send('World!'),
);
telegram.updates.startPolling();