0% found this document useful (0 votes)
288 views

Personal Assistant With Telegram & Arduino

This document describes how to create a personal assistant bot using the Telegram messaging app and an Arduino board. It explains that Telegram is an open-source messaging app similar to WhatsApp that focuses on security and privacy. The document instructs the reader to install Telegram on their device and start a conversation with @BotFather, which allows users to create new bots. It states that after starting a conversation with BotFather, it will provide commands to interact with it and create a new bot.

Uploaded by

Abhijit Pattnaik
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
288 views

Personal Assistant With Telegram & Arduino

This document describes how to create a personal assistant bot using the Telegram messaging app and an Arduino board. It explains that Telegram is an open-source messaging app similar to WhatsApp that focuses on security and privacy. The document instructs the reader to install Telegram on their device and start a conversation with @BotFather, which allows users to create new bots. It states that after starting a conversation with BotFather, it will provide commands to interact with it and create a new bot.

Uploaded by

Abhijit Pattnaik
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

let's make Explore(/tag/typeid/) Publish(/about/create.

jsp) You (/you/)

Classes(/classes/) NEW!
Featured: share (/tag/typeid/categorycraft/channelleather/)
what you make Leather(/tag/typeid/categorycraft/channelleather/)
(/)
(/tag/typeid/categoryoutside/channelcamping/) Camping(/tag/typeid/categoryoutside/channelcamping/) (/id/intel/) IntelIoT(/id/intel/)

(/id/Fusion/) Fusion360(/id/Fusion/)

AboutThisInstructable

Posted:
8 4,791 views Mar19,2016

59 favorites License:

racurcio
(/member/racurcio/)
Follow 6

(/member/racurcio/)

Morebyracurcio:

(/file/FXI1OEIILY0PJPH/)
(/id/Personal

Hellofolks!
AfewmonthsagoIheardaboutaprojectthatusedaninstantmessengerbotto AssistantWithTelegramArduino/)
createasystemthatwouldautomaticallyprocessandorganizepizza'sorders
sentbythecostumersviaWhatsapp.Iwaslike...wow!Givethatmanacookie! Tags: Telegram(/howto/Telegram/)
SoItooksometimetoexplorearoundbotsandhowtocodethem.Withalittle arduino(/howto/arduino/) diy(/howto/diy/)
PersonalAssistantwithTelegram&Arduino.
bitofresearchIdiscoveredthatusingaTelegrambotwouldmakeiteasierfor
byracurcio(/member/racurcio/)
metoprogrammybotsincethereisalotofsupportforthemakersthathave
Download
programming(/howto/programming/)
h(/id/PersonalAssistantWithTelegramArduino/) 9Steps .
interestinbots.AndBecauseforthisprojecttheTelegramappisusedtosend
commandsthereiszeroandroidprogramming Collection IMadeit! Favorite Share
Addinstructableto:

Checkouttheprojectworking!:D ; Group

Personal Assistant with Telegram & Arduino.


Related

TreelegramHacka
ChristmasTreeLightsFrom
AnywhereintheWorld!
(/id/TreelegramHacka
(/id/TreelegramChristmasTreeLightsFrom
TeleLabMonitoryourlab
withTelegram,Node.jsand
Websockets(/id/TeleLab
Monitoryourlabwith
(/id/TeleLab TelegramNodejsand/)
unKnocki(/id/UnKnocki/)
byraghav_anand98
(/member/raghav_anand98/)

(/id/UnKnocki/)
TelegramBotwithIntel
Edison(/id/TelegramBot
withIntelEdison/)
bysabas1080
(/id/Telegram (/member/sabas1080/)
TelegramwithIntelEdison
andPython(/id/Telegram
Step1:Firstthingsfirst withIntelEdisonand
Python/)
Thisinstructableisabouthowtocreateanduseapersonalassistant(bot)using (/id/Telegram byjuliaat(/member/juliaat/)
theTelegramapp.Forthoseofyouthatneverheardaboutit,theTelegramapp
isverysimilartoWhatsApp(evenbettercoughcough)howevertherearea Replay
few(andmeaningful)differences.Telegramusesanopensourcecodecreated
withahugefocusonsecurityandprivacy.

Theinitialideaforusingthisbotprojectwastocreateasolutionthatwouldallow
metotalktomyhouse(Howisthetemperatureinmyroom?,Turnonthelights
Isthedoorclosed?,DEFCON4DOUBLETAKE!!).Itisntunusualtoseeprojects
workingwithhomeautomationusingArduino,WiFishields(orEthernet)butI
didntwanttocrossthatknownpathagainbecausewhatwouldbeeasierthan
*T&Capply

havingallthepowerinasimplechat?SoIdecidedtocreatemybot!Allthistalk
aboutbotsbut.Attheendoftheday,whatisaTelegrambot?Abotisa
Telegramaccountcontrolledbyasoftware.Sohowaboutcreatingourownbot?

Letsbegin!

Step2:InstallingTelegram
TocreateaTelegramaccount.Justinstalltheappinyourdevice(Playstore
(https://play.google.com/store/apps/details?
id=org.telegram.messenger&hl=en)/iTunes
(https://itunes.apple.com/en/app/telegrammessenger/id686449807?
mt=8)/TelegramDesktop(https://desktop.telegram.org/)).Easypeasyright?Just
signupusingyourcellphonenumberandyouwouldbegoodtogo.

Onceyouraccountexistsstartaconversationwith@BotFather(Theonebotto
rulethemall).BotFatherisasortofmainbotthatallowsuserstocreatenew
botsandtostartaconversationwithhimjustfollowthelink
PersonalAssistantwithTelegram&Arduino. byracurcio(/member/racurcio/)
https://telegram.me/botfather(https://telegram.me/botfather)orsearchfor
Download h(/id/PersonalAssistantWithTelegramArduino/) 9Steps .
botfatherinyourcontactsandstartaconversation.Oncetheconversationis
opentherewillbeabutton/startatthebottomofthechat. Collection IMadeit! Favorite Share

Step3:Botfather
AfterstartingaconversationwithBotFatheritwillsendtheavailablecommands
totalkinteractwithBotFather.Becausewewanttocreateabotletsgoahead
andsend:
/newbotAsyoucanseeintheimagebelow,BotFatherwillrequiresome
informationaboutourbot.(1)Howthebotwillbecalledand(2)whatisthebot
username.

Ifeverythingworkedwell,thenewbotwasborn.Thebotismainlyreadytosend
andreceivemessagesfromthebot.

PersonalAssistantwithTelegram&Arduino. byracurcio(/member/racurcio/)
Step4:Installingtools(LINUX)
Download h(/id/PersonalAssistantWithTelegramArduino/) 9Steps .

Collection
Nowthatthebotisreadytoreceivesomeinstructions,wehavetokeepinmind IMadeit! Favorite Share
thatinordertoprogramthebotsometoolswillbeneeded.Hereisalistofthe
commandsnecessaryfortheinstallationofthetools:

$sudoaptgetinstallpython3
$sudoaptgetinstallpython3pip
$sudopip3installtelepot
$sudopip3installtelepotupgrade#UPGRADE

Thecommandsabovewillinstallthetelepotpythonmoduleforthoseusing
Linux.

Step5:Installingtools(WINDOWS)
Forwindowsusersyoucandownloadandinstallpythonbyaccessingthelink
here(https://www.python.org/downloads/).
Onceyouhaveinstalledthepython(Irecommendtheversion3.4)thenextstep
istoinstalltheTelepotpackageyoushouldopenaterminalandinsertthe
followingcommand:

pympipinstalltelepot

Youshouldgetanoutputasfollows:

Step6:Pythoncode
TelepotisapythonAPItoworkwithTelegrambots.Formoredetails,
documentationandsomecodesabouttheAPIcheckouttheGitHubhere
(https://github.com/nickoala/telepot).

Letsstartwithahelloworldofthebotsworld.Wellbuildabotthatwillrespond
tothe/hellomessage.
PersonalAssistantwithTelegram&Arduino. byracurcio(/member/racurcio/)
Download
#!/usr/bin/python h(/id/PersonalAssistantWithTelegramArduino/) 9Steps .
importtelepot,time
Collection IMadeit! Favorite Share
defhandle(msg):
content_type,chat_type,chat_id=telepot.glance(msg)

if(content_type=='text'):
command=msg['text']
print('Gotcommand:%s'%command)

if'/hello'incommand:
bot.sendMessage(chat_id,"Hello,doyouhaveanycommandsfortoday?")

#CreatesabotusingthetokenprovidedbyBotFather
bot=telepot.Bot('16843XXXX:AAGGq99MLWOknqCx66V5s2XXXXXXXXXXXXX')

#Addthehandlefunctiontobecalledeverynewreceivedmessage
bot.message_loop(handle)

#Waitfornewmessages
while1:
time.sleep(20)

Beawarethatinyourowncodeyouhavetochangethetokenintheline15by
thetokenprovidedbybotFather.Savethefilethenameassistant.py.

Runthecodethoughyourterminalusing

$python3assistant.py

Oncethecodeiskickingitispossibletotestourbotbysendingamessage
throughanydevicetoourbot(youcanfindhimusingtheusernamethatwas
providedtobotFatherearlier).

assistant.py(/files/orig/FQ0/0YS6/ILV8B35Q/FQ00YS6ILV8B35Q.py)

Step7:More...moremore!

PersonalAssistantwithTelegram&Arduino. byracurcio(/member/racurcio/)
Thebotwasabletoreceivemessagesandreplytoanspecificmessageas
Download h(/id/PersonalAssistantWithTelegramArduino/) 9Steps .
definedinthecode.Inthebackgroundthepythoncodewashandlingallthe
Collection
inputsandoutputsoftheoperation.Aswecanseethecodeforcontrollingabot IMadeit! Favorite Share
isprettystraightforward.

Nowthatthebotisworking,howaboutenhancingsomeofitsabilities?Using
anArduinoandarelayIdecidedtotestifthebotwouldbeabletocontrolalamp
remotelyinmyhouseandhereistheresult.Forthisideathefollowing
schematicwasusedtoconnectanArduinotoarelaymoduleandalamp.

ThecodefortheArduinoisverysimple:

constintlightPin=6
unsignedintdata
voidsetup(){
Serial.begin(9600)
pinMode(lightPin,OUTPUT)

}

voidloop(){
while(Serial.available()>0){
data=Serial.read()
if(data=='Y')digitalWrite(lightPin,HIGH)
if(data=='N')digitalWrite(lightPin,LOW)
}

}

control.ino(/files/orig/FL1/UHGB/ILV8B36B/FL1UHGBILV8B36B.ino)
PersonalAssistantwithTelegram&Arduino. byracurcio(/member/racurcio/)
Download h(/id/PersonalAssistantWithTelegramArduino/) 9Steps .

Step8:Controllingthelamp Collection IMadeit! Favorite Share

ForthissetuptheserialportwasusedtointerfacethebotcodeandtheArduino.
ThecodewillsendthecharacterYtotheArduinoforturningontherelay
moduleandNtoturnofftherelaymoduleturningoffthelight.

OncetheArduinoisproperlyprogrammedandconnecteditistimetoworkout
thecodeforthebot.

#!/usr/bin/python
importtelepot,time,serial
ser=serial.Serial('/dev/ttyACM0',9600)

defhandle(msg):

userName=msg['from']['first_name']+""+msg['from']['last_name']

content_type,chat_type,chat_id=telepot.glance(msg)

if(content_type=='text'):
command=msg['text']
print('Gotcommand:%s'%command)

if'/hello'incommand:
bot.sendMessage(chat_id,"Hello"+userName+",howareyoudoingtoday?")

if'/lamp_on'incommand:
ser.write(b'Y')
bot.sendMessage(chat_id,"LampON")

if'/lamp_off'incommand:
ser.write(b'N')
bot.sendMessage(chat_id,"LampOFF")

#CreateabotusingthetokengivenbyBotFather

Theserialmodulehastobeimportedinordertocommunicatethepythoncode
withtheArduinoserialport.Itisimportanttonotethattheline#3isspecificto
theportthattheArduinoisconnectedandthislinemustbemodifiedaccordingly
tothenecessity.
Savethecodeanditwillbereadytobetested!

assistant2.py(/files/orig/FA3/KRAL/ILV8B35U/FA3KRALILV8B35U.py)

Step9:Don'tstopmenoooowww

PersonalAssistantwithTelegram&Arduino. byracurcio(/member/racurcio/)
Download h(/id/PersonalAssistantWithTelegramArduino/) 9Steps .

Collection IMadeit! Favorite Share

(/file/FUNGMZXILZG5GKF/)

Forthisproject,asanexample,Icouldturnonandoffalamp...butitispossible
toextendthisproject"Toinfinityandbeyond"!Myideatoextendthisprojectis
toimplementasecuritysystemcontrolledbyaraspberrypiandIwouldinterface
thissystembyusingaTelegramchat.Doingthatitispossibletorequestand
sendinformationtomyhousesuchassecuritycameraimages,temperature,
securitycameravigilance,andmuchmore.
Ifyouareinterestedandwanttolearnmoreaboutbots,therearetensofbots
availableontheinternet(withthecodeavailable!).
Someofthosewillbelinkedbelow
Tablewiththebestbots
(https://docs.google.com/spreadsheets/d/1uQP3f2bWuPapTn_1FUcL67jW9
MwLzSjysji39pmyUxY/edit?usp=sharing).Thistablewascreatedfroma
subreddit
(https://www.reddit.com/r/TelegramBots/comments/3b0glc/master_list_of_tel
egram_bots_will_be_updated/)aboutTelegrambots.
Telepot(https://github.com/nickoala/telepot).GithuboftheAPIusedinthis
project.
Youcancheckoutaportugueseversionofthisprojectat

PersonalAssistantwithTelegram&Arduino. byracurcio(/member/racurcio/)

You might also like