Skip to main content

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

Release files for yalice 0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for yalice 0.1
File Size Uploaded
yalice-0.1.tar.gz 4.6 kB Details

Release files / yalice-0.1.tar.gz

Download URL yalice-0.1.tar.gz
Size 4.6 kB
Tags Source
SHA-256 checksum
How to use checksums
05dc3a775cd8828cc606511b330ab03cc8c11b60fc1ce952ef0f4dae1b0aa7a3
BLAKE2b-256 checksum
How to use checksums
fa7d129c63d0e2c74b65c864b7452bff1e7bc4935d500d630c7be7d978145fb9
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

0.1 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page