Heydjbot

 

Spotify & Telegram.

Una historia de amor

Jose María Álvarez

@mongonauta

https://github.com/mongonauta/heydjbot

Heydjbot: Spotify & Telegram

PyconES 2016 - Almeria

Quién soy?

https://twitter.com/mongonauta

http://github.com/mongonauta

Heydjbot: Spotify & Telegram

PyconES 2016 - Almeria

Qué os voy a contar?

  1. Qué narices es un bot?
  2. Bots en Telegram
  3. Como funciona la API de Spotify
  4. Spotify meets Telegram
  5. Heydjbot

Heydjbot: Spotify & Telegram

PyconES 2016 - Almeria

1. Qué narices es un bot?

Heydjbot: Spotify & Telegram

PyconES 2016 - Almeria

1. Qué narices es un bot?

"Un bot —palabra que resulta de una aféresis practicada sobre robot— es un programa diseñado para interactuar con otros programas, servicios de Internet o seres humanos de manera semejante a como lo haría una persona. En Wikipedia y otros proyectos basados en el software MediaWiki, los bots se utilizan para simplificar o automatizar tareas cuya realización manual resultaría muy tediosa."

Heydjbot: Spotify & Telegram

PyconES 2016 - Almeria

2. Bots en Telegram - Basics

  • Un bot para crear bots (el sueño de Christopher Nolan)
  • Puedes configura tu Bot usando comandos como setName, setUserPic...
  • https://api.telegram.org/bot<token>/METHOD_NAME

Heydjbot: Spotify & Telegram

PyconES 2016 - Almeria

2. Bots en Telegram - Librería

  • Handlers: RegexHandler, MessageHandler, CommandHandler
  • Máquina de estados: ConversationHandler
  • update.message.from_user
  • Markups: ReplyKeyboardMarkup
  • Stickers, Images...

Heydjbot: Spotify & Telegram

PyconES 2016 - Almeria

2. Bots en Telegram - Basic Demo

def basic_command(bot, update):

    user = update.message.from_user
    logger.info(
        'User %s' % user.first_name
    )
    update.message.reply_text(
        'Hello %s' % user.first_name
​    )
    return None
def main():

    updater = Updater(TOKEN)
​    dp = updater.dispatcher
    
    ...
​    dp.add_handler(CommandHandler(
        'hello',
        basic_command
    ))​
    dp.add_error_handler(error)
    updater.start_polling()
    update.idle()​

if __name__ == '__main__':
    main()
 

Heydjbot: Spotify & Telegram

PyconES 2016 - Almeria

3. Como funciona la API de Spotify

Our Web API lets your applications fetch data from the Spotify music catalog and manage user’s playlists and saved music.

  • REST API
  • OAUTH
  • JSON
  • "Public endpoints": Search song/artist
  • "Private endpoints": User playlists and info

Heydjbot: Spotify & Telegram

PyconES 2016 - Almeria

3. Como funciona la API de Spotify - Registrar nuestro Bot

Heydjbot: Spotify & Telegram

PyconES 2016 - Almeria

3. Como funciona la API de Spotify - Ejemplo 1 

curl -X GET "https://api.spotify.com/v1/search?q=metallica&type=artist"
{
  "artists" : {
    "href" : "...",
    "items" : [ {
      "external_urls" : {
        "spotify" : "https://open.spotify.com/artist/2ye2Wgw4gimLv2eAKyk1NB"
      },
      "followers" : { "href" : null, "total" : 2239947 },
      "genres" : [ ... ],
      "href" : "https://api.spotify.com/v1/artists/2ye2Wgw4gimLv2eAKyk1NB",
      "id" : "2ye2Wgw4gimLv2eAKyk1NB",
      "images" : [...],
      "name" : "Metallica",
      "popularity" : 82,
      "type" : "artist",
      "uri" : "spotify:artist:2ye2Wgw4gimLv2eAKyk1NB"
    }],
    "limit" : 20 ...    
  }
}

Heydjbot: Spotify & Telegram

PyconES 2016 - Almeria

3. Como funciona la API de Spotify - Ejemplo 2

curl -X GET "https://api.spotify.com/v1/me" -H "Authorization: Bearer {your access token}"
{
  "birthdate": "1937-06-01",
  "country": "SE",
  "display_name": "JM Wizzler",
  "email": "email@example.com",
  "external_urls": { "spotify": "https://open.spotify.com/user/wizzler" },
  "followers" : { "href" : null, "total" : 3829 },
  "href": "https://api.spotify.com/v1/users/wizzler",
  "id": "wizzler",
  "images": [{
      "height": null,
      "url": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-frc3/t1.0-1/1970403_10152215092574354_1798272330_n.jpg",
      "width": null
  }],
  "product": "premium",
  "type": "user",
  "uri": "spotify:user:wizzler"
}

Heydjbot: Spotify & Telegram

PyconES 2016 - Almeria

4. Spotify meets Telegram

Arquitectura

Heydjbot: Spotify & Telegram

PyconES 2016 - Almeria

4. Spotify meets Telegram

Demo Time

Heydjbot: Spotify & Telegram

PyconES 2016 - Almeria

4. Spotify meets Telegram

Problemas

Heydjbot: Spotify & Telegram

PyconES 2016 - Almeria

5. HeydjBot

Heydjbot: Spotify & Telegram

PyconES 2016 - Almeria

5. HeydjBot v2

Heydjbot: Spotify & Telegram

PyconES 2016 - Almeria

Referencias

Heydjbot: Spotify & Telegram

PyconES 2016 - Almeria

We are hiring!!!!

Heydjbot: Spotify & Telegram

PyconES 2016 - Almeria

Preguntas????

PyconES 2016 - Telegram meets Spotify

By Jose Maria Alvarez Rey

PyconES 2016 - Telegram meets Spotify

  • 3,293