def get_random_announcements(): announcements = random.sample( sample_announcements.announcements, random.randint(2, len(sample_announcements.announcements) - 1)) response_text = '' response_speech = '' if len(announcements) == 0: response = random.choice(NO_UNREAD_ANNOUNCEMENTS) return Response(response) elif len(announcements) == 1: response = random.choice(UNREAD_ANNOUNCEMENT) response_text = response[0].format('Susan') response_speech = response[1].format('Susan') else: response = random.choice(UNREAD_ANNOUNCEMENTS) response_text = response[0].format('Susan', len(announcements)) response_speech = response[1].format('Susan', len(announcements)) items = [] for a in announcements: items.append(getAnnouncementItem(a)) return Response(response_text).speech(response_speech, response_text).select( response_text, items)
def select_id(session, request): error_text = 'Error, course not found' courseId = None for context in request.get('queryResult').get('outputContexts'): if context.get('name').endswith( 'actions_intent_option') and context.get('parameters').get( 'OPTION') is not None: option_value = context.get('parameters').get('OPTION') courseId = option_value[ option_value.startswith('course') and len('course') + 1:] if courseId is None: if request.get('queryResult').get('parameters').get('id') is not None: courseId = request.get('queryResult').get('parameters').get('id') else: return Response(error_text).text(error_text).build() ## duplicated in input.py select_cards = [] lessons = sample_lessons.courses_id_dict.get(courseId) logging.debug('courseId: %s, %d lessons in course', courseId, len(lessons)) if lessons is not None: for lesson in lessons: card = Item('lesson ' + lesson.id, lesson.name, lesson.description) select_cards.append(card) response_text = random.choice(LESSON_SELECT) context = OutputContext(session, OUT_CONTEXT_LESSON, type=OUT_CONTEXT_LESSON) return Response(response_text).text(response_text).select( response_text, select_cards).outputContext(context).build()
def get_notification(session, request, id): if id: for announcement in sample_announcements.announcements: if announcement.id == id: return Response(announcement.text).build() return get_random_announcements().build()
def read(session, request): anthem = random.choice(ANTHEM) userContext = UserContext() return Response(anthem[0].format(userContext.name))\ .speech(anthem[1].format(userContext.name), anthem[0].format(userContext.name))\ .userStorage(userContext.toJson())\ .suggestions(WELCOME_SUGGESTIONS).build()
def course_id(session, courseId): response_text = random.choice(LESSON_SELECT) context = OutputContext(session, OUT_CONTEXT_COURSE, type=OUT_CONTEXT_COURSE) select_cards = [] lessons = sample_lessons.courses_id_dict.get(courseId.strip()) logging.debug('courseId: %s, %d lessons in course', courseId, len(lessons)) if lessons is not None: for lesson in lessons: card=Item('lesson '+lesson.id, lesson.name, lesson.description) select_cards.append(card) return Response(response_text).text(response_text).select(response_text, select_cards).outputContext(context).build()
def lesson_id(session, lessonId): logging.debug('lessonId: %s', lessonId) response_text = random.choice(LESSON_ACTIVITY_SELECT) context = OutputContext(session, OUT_CONTEXT_LESSON_ACTIVITY, type=OUT_CONTEXT_LESSON_ACTIVITY) select_cards = [] lesson = sample_lessons.lesson_id_dict.get(lessonId.strip()) if lesson is not None: for m in lesson.materials: logging.debug('activity type=%s, %s',type(m), m) if isinstance(m, Video): select_cards.append(Item(id='activity '+m.id, title=m.title, imageUri=m.imageUri)) elif isinstance(m, Text): select_cards.append(Item(id='activity '+m.id, title=m.title, imageUri=m.imageUri)) elif isinstance(m, Link): select_cards.append(Item(id='activity '+m.id, title=m.title, imageUri=m.imageUri)) elif isinstance(m, Audio): select_cards.append(Item(id='activity '+m.id, title=m.title, imageUri=m.imageUri)) elif isinstance(m, Quiz): select_cards.append(Item(id='activity '+m.id, title=m.title, imageUri=m.imageUri)) return Response(response_text).text(response_text).select(response_text, select_cards).outputContext(context).build() error_text = 'Error, lesson not found' return Response(error_text).text(error_text).build()
def list_all(session, request): permissions = [] oriReq = request.get('originalDetectIntentRequest') if oriReq.get('payload') and oriReq.get('payload').get( 'user') and oriReq.get('payload').get('user').get('permissions'): permissions = oriReq.get('payload').get('user').get('permissions') try: if permissions is not None and len( permissions) > 0 and permissions.index("UPDATE", 0, len(permissions)) > -1: return get_random_announcements().build() else: response_text = "Get immediate alerts for school updates?" return Response(response_text).permissions( response_text, ["UPDATE"], "input.get_notification").build() except: return get_random_announcements().build()
def list_all(session, request): response_text = random.choice(COURSE_SELECT) select_cards = [] grade = 8 #get user grade for course in sample_courses.courses: if course.grade == grade: card = Item(id='course ' + course.id, title=course.name, description=course.description, imageUri=course.imageUri, imageText=course.name) select_cards.append(card) context = OutputContext(session, OUT_CONTEXT_COURSE, type=OUT_CONTEXT_COURSE) return Response(response_text).text(response_text).select( response_text, select_cards).outputContext(context).build()