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 hashes)

Uploaded Source

Supported by

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