SlideShare ist ein Scribd-Unternehmen logo
1 von 13
Downloaden Sie, um offline zu lesen
Telegram Bots
WHOAMI
Front End Lead @ Rails Reactor
github.com/viattik
twitter.com/vi_attik
bots, bots, bots
И чо?
Creating Bot
Creating Bot
var TelegramBot = require('node-telegram-bot-api'),

telegram = new TelegramBot("YOUR_BOT_TOKEN", { polling: true });



telegram.on("text", (message) => {

telegram.sendMessage(message.chat.id, "Hello world");

});
Creating Bot
function getReply(text) {

if (text.includes('ничо')) {

return 'Вот и хорошо';

} else if (text.includes('/start')) {

return 'Давай, расскажи мне о своих проблемах.';

} else {

return 'И чо?';

}

}



telegram.on("text", (message) => {

const text = message.text.toLowerCase();

const reply = getReply(text);

telegram.sendMessage(message.chat.id, reply, {

parse_mode: "Markdown"

});

});
Support Bot
// Telegram sent message
telegram.on("text", (message) => {

const text = message.text;

const id = message.chat.id;

let chat = chats[id];

if (!chat && text === '/support') {

chats[id] = chat = {

from: message.from,

messages: []

}

} else if (chat && text === '/end_support') {

chats[id] = chat = undefined;

}

if(chat) {

chat.messages.push({ sender: 0, text });

}

syncToBrowser();

});
Support Bot
wsServer.on('request', function(request) {

let connection = request.accept(null, request.origin);

connections.push(connection);

connection.sendUTF(JSON.stringify(chats));



// Browser sent message

connection.on('message', function(message) {

const { id, text } = JSON.parse(message.utf8Data);

const chat = chats[id];

if (!chat) { return; }



chat.messages.push({ sender: 1, text });

telegram.sendMessage(id, text);

});

});
DEMO
https://youtu.be/1xhgMeV4ZCs
Inline Bots
Links
https://core.telegram.org/bots
https://telegram.me/botfather
https://github.com/viattik/support-demo-bot
https://medium.com/codeday-by-studentrnd/intro-to-node-js-
making-a-telegram-bot-964b8cfe1129

Weitere ähnliche Inhalte

Was ist angesagt?

Etherem ~ agvm
Etherem ~ agvmEtherem ~ agvm
Etherem ~ agvm
gha sshee
 
C++ course start
C++ course startC++ course start
C++ course start
Net3lem
 
Migrations With Transmogrifier
Migrations With TransmogrifierMigrations With Transmogrifier
Migrations With Transmogrifier
Rok Garbas
 
JavaScript Loop: Optimization of Weak Typing
JavaScript Loop: Optimization of Weak TypingJavaScript Loop: Optimization of Weak Typing
JavaScript Loop: Optimization of Weak Typing
Janlay Wu
 

Was ist angesagt? (20)

WebSocket 实时推特流
WebSocket 实时推特流WebSocket 实时推特流
WebSocket 实时推特流
 
関西アンカンファレンス PHP ではじめるテストコード
関西アンカンファレンス PHP ではじめるテストコード関西アンカンファレンス PHP ではじめるテストコード
関西アンカンファレンス PHP ではじめるテストコード
 
Etherem ~ agvm
Etherem ~ agvmEtherem ~ agvm
Etherem ~ agvm
 
Introducere In Java Jx
Introducere In Java JxIntroducere In Java Jx
Introducere In Java Jx
 
Javascript for loop
Javascript for loopJavascript for loop
Javascript for loop
 
Are we ready to Go?
Are we ready to Go?Are we ready to Go?
Are we ready to Go?
 
Knee-deep in C++ s... code
Knee-deep in C++ s... codeKnee-deep in C++ s... code
Knee-deep in C++ s... code
 
Os Secoske
Os SecoskeOs Secoske
Os Secoske
 
Kotlin, a modern language for modern times
Kotlin, a modern language for modern timesKotlin, a modern language for modern times
Kotlin, a modern language for modern times
 
Instalación de emu8086 y compilados
Instalación de emu8086 y compiladosInstalación de emu8086 y compilados
Instalación de emu8086 y compilados
 
C++ course start
C++ course startC++ course start
C++ course start
 
Go ahead, make my day
Go ahead, make my dayGo ahead, make my day
Go ahead, make my day
 
Migrations With Transmogrifier
Migrations With TransmogrifierMigrations With Transmogrifier
Migrations With Transmogrifier
 
Django debugging
Django debuggingDjango debugging
Django debugging
 
Bash script (mask off remix)
Bash script (mask off remix)Bash script (mask off remix)
Bash script (mask off remix)
 
Golang concurrency design
Golang concurrency designGolang concurrency design
Golang concurrency design
 
The Ring programming language version 1.6 book - Part 25 of 189
The Ring programming language version 1.6 book - Part 25 of 189The Ring programming language version 1.6 book - Part 25 of 189
The Ring programming language version 1.6 book - Part 25 of 189
 
JavaScript Loop: Optimization of Weak Typing
JavaScript Loop: Optimization of Weak TypingJavaScript Loop: Optimization of Weak Typing
JavaScript Loop: Optimization of Weak Typing
 
Laying Pipe with Transmogrifier
Laying Pipe with TransmogrifierLaying Pipe with Transmogrifier
Laying Pipe with Transmogrifier
 
Introduction to go
Introduction to goIntroduction to go
Introduction to go
 

Andere mochten auch

Andere mochten auch (20)

Integrating Telegram Bots with Ruby on Rails
Integrating Telegram Bots with Ruby on RailsIntegrating Telegram Bots with Ruby on Rails
Integrating Telegram Bots with Ruby on Rails
 
Telegram
TelegramTelegram
Telegram
 
#web4business: Francesco ambrosino "Telegram 4 business"
#web4business: Francesco ambrosino "Telegram 4 business"#web4business: Francesco ambrosino "Telegram 4 business"
#web4business: Francesco ambrosino "Telegram 4 business"
 
Gaya hidup sihat ala nature
Gaya hidup sihat ala natureGaya hidup sihat ala nature
Gaya hidup sihat ala nature
 
PS201-Chapter five
PS201-Chapter fivePS201-Chapter five
PS201-Chapter five
 
PS201-Chapter two
PS201-Chapter twoPS201-Chapter two
PS201-Chapter two
 
Telegram - восходящий тренд Вебинар WebPromoExperts #312
Telegram - восходящий тренд Вебинар WebPromoExperts #312Telegram - восходящий тренд Вебинар WebPromoExperts #312
Telegram - восходящий тренд Вебинар WebPromoExperts #312
 
Designing the Conversation [SmashingConf 2016]
Designing the Conversation [SmashingConf 2016]Designing the Conversation [SmashingConf 2016]
Designing the Conversation [SmashingConf 2016]
 
PS201-Chapter one
PS201-Chapter onePS201-Chapter one
PS201-Chapter one
 
Python - Telegram
Python - TelegramPython - Telegram
Python - Telegram
 
How to share a PowerPoint Presentation using SlideShare
How to share a PowerPoint Presentation using SlideShareHow to share a PowerPoint Presentation using SlideShare
How to share a PowerPoint Presentation using SlideShare
 
101 Conversational User Interfaces
101 Conversational User Interfaces 101 Conversational User Interfaces
101 Conversational User Interfaces
 
Chat Bots, ChatOps and the Conversational User Interface (CUI)
Chat Bots, ChatOps and the Conversational User Interface (CUI)Chat Bots, ChatOps and the Conversational User Interface (CUI)
Chat Bots, ChatOps and the Conversational User Interface (CUI)
 
Converations on conversational Ux
Converations on conversational UxConverations on conversational Ux
Converations on conversational Ux
 
Conversational interfaces - beyond the hype
Conversational interfaces - beyond the hypeConversational interfaces - beyond the hype
Conversational interfaces - beyond the hype
 
AI and Python: Developing a Conversational Interface using Python
AI and Python: Developing a Conversational Interface using PythonAI and Python: Developing a Conversational Interface using Python
AI and Python: Developing a Conversational Interface using Python
 
Bots are the New Apps: Building with the Bot Framework & Language Understanding
Bots are the New Apps: Building with the Bot Framework & Language UnderstandingBots are the New Apps: Building with the Bot Framework & Language Understanding
Bots are the New Apps: Building with the Bot Framework & Language Understanding
 
Chatbots, Conversational Interfaces, and the Rise of Messaging platforms
Chatbots, Conversational Interfaces, and the Rise of Messaging platformsChatbots, Conversational Interfaces, and the Rise of Messaging platforms
Chatbots, Conversational Interfaces, and the Rise of Messaging platforms
 
Designing for conversation
Designing for conversationDesigning for conversation
Designing for conversation
 
An Introduction To Chat Bots
An Introduction To Chat BotsAn Introduction To Chat Bots
An Introduction To Chat Bots
 

Ähnlich wie Telegram bots

Whats new in_csharp4
Whats new in_csharp4Whats new in_csharp4
Whats new in_csharp4
Abed Bukhari
 
Here is a blueJ project there are three classes.import java.util.A.pdf
Here is a blueJ project there are three classes.import java.util.A.pdfHere is a blueJ project there are three classes.import java.util.A.pdf
Here is a blueJ project there are three classes.import java.util.A.pdf
almonardfans
 
Software Transactioneel Geheugen
Software Transactioneel GeheugenSoftware Transactioneel Geheugen
Software Transactioneel Geheugen
Devnology
 

Ähnlich wie Telegram bots (20)

How To Build A Telegram Bot Using NodeJS, Express and MongoDB
How To Build A Telegram Bot Using NodeJS, Express and MongoDBHow To Build A Telegram Bot Using NodeJS, Express and MongoDB
How To Build A Telegram Bot Using NodeJS, Express and MongoDB
 
How I taught the messenger to tell lame jokes
How I taught the messenger to tell lame jokesHow I taught the messenger to tell lame jokes
How I taught the messenger to tell lame jokes
 
Bots: Basics @ Javascript Tonight, 2017.09.22
Bots: Basics @ Javascript Tonight, 2017.09.22Bots: Basics @ Javascript Tonight, 2017.09.22
Bots: Basics @ Javascript Tonight, 2017.09.22
 
Whats new in_csharp4
Whats new in_csharp4Whats new in_csharp4
Whats new in_csharp4
 
Desafios do Profissionalismo Ágil
Desafios do Profissionalismo ÁgilDesafios do Profissionalismo Ágil
Desafios do Profissionalismo Ágil
 
Here is a blueJ project there are three classes.import java.util.A.pdf
Here is a blueJ project there are three classes.import java.util.A.pdfHere is a blueJ project there are three classes.import java.util.A.pdf
Here is a blueJ project there are three classes.import java.util.A.pdf
 
Writing a slack chatbot mxlos
Writing a slack chatbot mxlosWriting a slack chatbot mxlos
Writing a slack chatbot mxlos
 
Advanced Java - Practical File
Advanced Java - Practical FileAdvanced Java - Practical File
Advanced Java - Practical File
 
Fake My Party
Fake My PartyFake My Party
Fake My Party
 
Writing a slack chatbot DrupalCampLA
Writing a slack chatbot DrupalCampLAWriting a slack chatbot DrupalCampLA
Writing a slack chatbot DrupalCampLA
 
JUnit and Mockito tips
JUnit and Mockito tipsJUnit and Mockito tips
JUnit and Mockito tips
 
TDD per Webapps
TDD per WebappsTDD per Webapps
TDD per Webapps
 
Multimethods
MultimethodsMultimethods
Multimethods
 
Software Transactioneel Geheugen
Software Transactioneel GeheugenSoftware Transactioneel Geheugen
Software Transactioneel Geheugen
 
servlets
servletsservlets
servlets
 
Imagine a world without mocks
Imagine a world without mocksImagine a world without mocks
Imagine a world without mocks
 
Hi, I need some one to help me with Design a client-server Chat so.pdf
Hi, I need some one to help me with Design a client-server Chat so.pdfHi, I need some one to help me with Design a client-server Chat so.pdf
Hi, I need some one to help me with Design a client-server Chat so.pdf
 
Bot builder v4 HOL
Bot builder v4 HOLBot builder v4 HOL
Bot builder v4 HOL
 
Little Big Ruby
Little Big RubyLittle Big Ruby
Little Big Ruby
 
How to build twitter bot using golang from scratch
How to build twitter bot using golang from scratchHow to build twitter bot using golang from scratch
How to build twitter bot using golang from scratch
 

Kürzlich hochgeladen

%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
masabamasaba
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 

Kürzlich hochgeladen (20)

%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 

Telegram bots