コード例 #1
0
ファイル: __init__.py プロジェクト: imclab/SiriServerPlugins
 def presentPossibleUsers(self, persons, language):
     root = UIAddViews(self.refId)
     root.dialogPhase = root.DialogPhaseClarificationValue
     utterance = UIAssistantUtteranceView()
     utterance.dialogIdentifier = "ContactDataResolutionDucs#disambiguateContact"
     utterance.text = responses['select'][language]
     utterance.speakableText = responses['select'][language]
     utterance.listenAfterSpeaking = True
     root.views = [utterance]
     # create a list with all the possibilities
     lst = UIDisambiguationList()
     lst.items = []
     lst.speakableSelectionResponse = "OK!"
     lst.listenAfterSpeaking = True
     lst.selectionResponse = "OK"
     root.views.append(lst)
     for person in persons:
         item = UIListItem()
         item.object = person
         item.selectionResponse = person.fullName
         item.selectionText = person.fullName
         item.title = person.fullName
         item.commands = [
             SendCommands([
                 StartRequest(
                     False, "^phoneCallContactId^=^urn:ace:{0}".format(
                         person.identifier))
             ])
         ]
         lst.items.append(item)
     return root
コード例 #2
0
ファイル: __init__.py プロジェクト: imclab/SiriServerPlugins
    def findPhoneForNumberType(self, person, numberType, language):
        # first check if a specific number was already requested
        phoneToMessage = None
        if numberType != None:
            # try to find the phone that fits the numberType
            phoneToMessage = filter(lambda x: x.label == numberType,
                                    person.phones)
        else:
            favPhones = filter(
                lambda y: y.favoriteVoice
                if hasattr(y, "favoriteVoice") else False, person.phones)
            if len(favPhones) == 1:
                phoneToMessage = favPhones[0]
        if phoneToMessage == None:
            # lets check if there is more than one number
            if len(person.phones) == 1:
                if numberType != None:
                    self.say(
                        errorNumberNotPresent.format(
                            numberTypesLocalized[numberType][language],
                            person.fullName))
                phoneToMessage = person.phones[0]
            else:
                # damn we need to ask the user which one he wants...
                while (phoneToMessage == None):
                    root = UIAddViews(self.refId)
                    root.dialogPhase = root.DialogPhaseClarificationValue

                    utterance = UIAssistantUtteranceView()
                    utterance.dialogIdentifier = "ContactDataResolutionDucs#foundAmbiguousPhoneNumberForContact"
                    utterance.speakableText = utterance.text = responses[
                        'selectNumber'][language].format(person.fullName)
                    utterance.listenAfterSpeaking = True

                    root.views = [utterance]

                    lst = UIDisambiguationList()
                    lst.items = []
                    lst.speakableSelectionResponse = "OK!"
                    lst.listenAfterSpeaking = True
                    lst.selectionResponse = "OK"
                    root.views.append(lst)
                    for phone in person.phones:
                        numberType = numberTypesLocalized[phone.label][
                            language] if phone.label in numberTypesLocalized else phone.label
                        item = UIListItem()
                        item.title = ""
                        item.text = u"{0}: {1}".format(numberType,
                                                       phone.number)
                        item.selectionText = item.text
                        item.speakableText = u"{0}  ".format(numberType)
                        item.object = phone
                        item.commands = [
                            SendCommands(commands=[
                                StartRequest(handsFree=False,
                                             utterance=numberType)
                            ])
                        ]
                        lst.items.append(item)

                    answer = self.getResponseForRequest(root)
                    numberType = self.getNumberTypeForName(answer, language)
                    if numberType != None:
                        matches = filter(lambda x: x.label == numberType,
                                         person.phones)
                        if len(matches) == 1:
                            phoneToMessage = matches[0]
                        else:
                            self.say(errorNumberTypes[language])
                    else:
                        self.say(errorNumberTypes[language])
        return phoneToMessage