Skip to main content

Python library for writing applications on yandex voice assistant

Project description

yalice

Python library for writing applications on yandex voice assistant

Getting started

pip install yalice

This library is a wrapper for Yandex Alice, not independent library for writing web based applications, so initialization takes in an object of the type Flask

from flask import Flask
from yalice import AliceBot, Message, Chat

app = Flask(__name__)
bot = AliceBot(app)

Your bot is going to be located on page '/post' If you would like to change this, you can change this by adding str parameter page

bot = AliceBot(app, page='/alice')

Also Yandex Alice can store user state and session state, pyalice give you abbility to save all that data automatically, but you can remove this abbility by adding bool parameter remember_state (to read more about states click here)

bot = AliceBot(app, page='/alice', remember_state=False)

message handler

To hangle messages you can use decorator message_handler

@bot.message_handler(start_handler=True)
def start(chat: Chat, message: Message):
    chat.send_message('Hello, I am annoying Alice. I will repeat each your word!')


@bot.message_handler(tokens=['stop'], filter_func=lambda message: message.request.type == 'ButtonPressed')
def stop(chat: Chat, message: Message):
    chat.send_message('It was a fun game!')
    chat.end_session()


@bot.message_handler(unknown_handler=True)
def echo(chat: Chat, message: Message):
    chat.send_message(message.request.original_utterance)
    chat.send_button('Stop!')

images

You can initialise images at the start to access easily There is 3 ways to initialise images

# 1 image at a time
bot.set_image('fox', '123456/123456')
bot.set_image('cat', '654321/654321')

# several images at a time
images = {
    'fox': '123456/123456',
    'cat': '654321/654321'
}
bot.set_images(images)

# several images at a time by using bot.images variable
bot.images = {
    'fox': '123456/123456',
    'cat': '654321/654321'
}

To send BigImage you can just use

chat.send_image('fox')

But if you would like to send ItemsList

chat.send_images('fox')
chat.send_images('cat')
chat.edit_images(header_text='Animals')

AliceBot object

AliceBot object stores information about images, sessions states and message_handlers. Now it has methods

  • set_image()
  • set_images()
  • message_handler()

Chat object

Chat object stores request to return. Now is has methods

  • send_message()
  • send_button()
  • send_image()
  • send_images()
  • edit_images()
  • end_session()
  • set_session_state()
  • set_user_state()

Message object

Message object is parsed json, to see json structure click here

Links

Telegram @cutefluffyfox
VK @cutefluffyfox
Expired by pyTelegramBotAPI

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yalice-0.1.tar.gz (4.6 kB view details)

Uploaded Source

File details

Details for the file yalice-0.1.tar.gz.

File metadata

  • Download URL: yalice-0.1.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.2

File hashes

Hashes for yalice-0.1.tar.gz
Algorithm Hash digest
SHA256 05dc3a775cd8828cc606511b330ab03cc8c11b60fc1ce952ef0f4dae1b0aa7a3
MD5 c48d0248b614dec4c5ca0f30f1a73133
BLAKE2b-256 fa7d129c63d0e2c74b65c864b7452bff1e7bc4935d500d630c7be7d978145fb9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page