Telegram-

IoT Telegram

8

, . , , , , . !

( ), , , , , , . , , , Google Home, ( ) .

, , , , . , , , , , , . , ?

? , , , , , ?

, . :

Telegram: , (Facebook Messenger, Whatsapp, Hangouts ..) API, , . , XMPP IRC . .

, , API/ . : -, , (, Whatsapp ).

, , Telegram : bot API , , , .

Platypush: Platypush Telegram . !


Telegram-

  • Botfather.
  • /start, /newbot . .
  • , API-. -, platypush.
 Telegram

platypush

1. platypush Telegram:

pip install 'platypush[http,db,telegram]'
apt-get install redis-server
[sudo] systemctl start redis
[sudo] systemctl enable redis

2. platypush , . , / - , , , , - / .

, Philips Hue, PiCamera.

3. Telegram ~/.config/platypush/config.yaml:

chat.telegram:
 api_token: <your bot token>
backend.chat.telegram:
 enabled: true

- (, , , ..) "". , , ..

, , :

/start

/help

/lights_on

/lights_off

/music_play

/music_pause

/music_next

/music_prev

/start_streaming

PiCamera

/stop_streaming

PiCamera

platypush config.yaml. :

Philips Hue, mopidy PiCamera:

pip install 'platypush[hue,mpd,picamera]'
# Hue lights configuration
light.hue:
 # Hue bridge IP address
 bridge: 192.168.1.10

 # Default groups to control
 groups:
 - Living Room

# MPD/Mopidy configuration
music.mpd:
 host: localhost
 port: 6600

# PiCamera configuration
camera.pi:
 vflip: False
 hflip: False

config.yaml, ~/.config/platypush/include/bot.yaml:

# /start command handler
event.hook.OnTelegramStartCmd:
 if:
 type: platypush.message.event.chat.telegram.CommandMessageEvent
 command: start
 then:
 - action: chat.telegram.send_message
 args:
 chat_id: ${chat_id}
 text: "Welcome! Type /help to see the available commands"

# /help command handler
event.hook.OnTelegramHelpCmd:
 if:
 type: platypush.message.event.chat.telegram.CommandMessageEvent
 command: help
 then:
 - action: chat.telegram.send_message
 args:
 chat_id: ${chat_id}
 text: "Available commands:\n

 - /lights_on\n
 - /lights_off\n
 - /music_play [resource]\n
 - /music_pause\n
 - /music_prev\n
 - /music_next\n
 - /start_streaming\n
 - /stop_streaming\n
 "

# /lights_on command handler
event.hook.OnTelegramLightsOnCmd:
 if:
 type: platypush.message.event.chat.telegram.CommandMessageEvent
 command: lights_on
 then:
 - action: light.hue.on
 - action: chat.telegram.send_message
 args:
 chat_id: ${chat_id}
 text: "Lights turned on"

# /lights_off command handler
event.hook.OnTelegramLightsOffCmd:
 if:
 type: platypush.message.event.chat.telegram.CommandMessageEvent
 command: lights_off
 then:
 - action: light.hue.off
 - action: chat.telegram.send_message
 args:
 chat_id: ${chat_id}
 text: "Lights turned off"

# /music_play command handler
event.hook.OnTelegramMusicPlayCmd:
 if:
 type: platypush.message.event.chat.telegram.CommandMessageEvent
 command: music_play
 then:
 - if ${cmdargs}:
 - action: music.mpd.play
 args:
 resource: cmdargs[0]
 - else:
 - action: music.mpd.play

 - action: chat.telegram.send_message
 args:
 chat_id: ${chat_id}
 text: "Music playing"

# /music_pause command handler
event.hook.OnTelegramMusicPauseCmd:
 if:
 type: platypush.message.event.chat.telegram.CommandMessageEvent
 command: music_pause
 then:
 - action: music.mpd.pause
 - action: chat.telegram.send_message
 args:
 chat_id: ${chat_id}
 text: "Music paused"

# /music_prev command handler
event.hook.OnTelegramMusicPrevCmd:
 if:
 type: platypush.message.event.chat.telegram.CommandMessageEvent
 command: music_prev
 then:
 - action: music.mpd.previous
 - action: chat.telegram.send_message
 args:
 chat_id: ${chat_id}
 text: "Playing previous track"

# /music_next command handler
event.hook.OnTelegramMusicNextCmd:
 if:
 type: platypush.message.event.chat.telegram.CommandMessageEvent
 command: music_next
 then:
 - action: music.mpd.next
 - action: chat.telegram.send_message
 args:
 chat_id: ${chat_id}
 text: "Playing next track"

# /start_streaming command handler
event.hook.OnTelegramCameraStartStreamingCmd:
 if:
 type: platypush.message.event.chat.telegram.CommandMessageEvent
 command: start_streaming
 then:
 - action: camera.pi.start_streaming
 args:
 listen_port: 2222

 - action: chat.telegram.send_message
 args:
 chat_id: ${chat_id}
 text: "PiCamera streaming started. Check it out with vlc tcp/h264://hostname:2222"


# /stop_streaming command handler
event.hook.OnTelegramCameraStopStreamingCmd:
 if:
 type: platypush.message.event.chat.telegram.CommandMessageEvent
 command: stop_streaming
 then:
 - action: camera.pi.stop_streaming
 - action: chat.telegram.send_message
 args:
 chat_id: ${chat_id}
 text: "PiCamera streaming stopped"

config.yaml:

include:
-include/bot.yaml

platypush:

# Manual start
platypush

# Service start
systemctl start platypush.service

, BotFather , :

. , - System Of A Down- Jet Pilot . . Telegram , ( Telegram chat_id , ).

platypush . :

2020-01-03 19:09:32,701| INFO|platypush|Received event: {"type": "event", "target": "turing", "origin": "turing", "id": "***", "args": {"type": "platypush.message.event.chat.telegram.CommandMessageEvent", "chat_id": your_chat_id, "message": {"text": "/help", ...}, "user": {"user_id": your_user_id, "username": "****", "is_bot": false, "link": "https://t.me/you", "language_code": "en", "first_name": "***", "last_name": "***"}, "command": "help", "cmdargs": []}}

chat_id - :

backend.chat.telegram:
 authorized_chat_ids:
 - your_user_id

, .

, !


?

Telegram - , .

Telegram, , :


50% Merion Academy