def createSmsSnippet(self, sms, addConfirmationOptions, dialogIdentifier, text, language): createAnchor = UIAddViews(self.refId) createAnchor.dialogPhase = createAnchor.DialogPhaseConfirmationValue # create a view to ask for the message askCreateView = UIAssistantUtteranceView() askCreateView.dialogIdentifier = dialogIdentifier askCreateView.text = askCreateView.speakableText = text askCreateView.listenAfterSpeaking = True # create a snippet for the sms snippet = SmsSnippet() if addConfirmationOptions: # create some confirmation options conf = UIConfirmSnippet({}) conf.requestId = self.refId confOpts = UIConfirmationOptions() confOpts.submitCommands = [ SendCommands( [conf, StartRequest(False, "^smsConfirmation^=^yes^")]) ] confOpts.confirmCommands = confOpts.submitCommands cancel = UICancelSnippet({}) cancel.requestId = self.refId confOpts.cancelCommands = [ SendCommands([ cancel, StartRequest(False, "^smsConfirmation^=^cancel^") ]) ] confOpts.denyCommands = confOpts.cancelCommands confOpts.denyText = snippetButtons['denyText'][language] confOpts.cancelLabel = snippetButtons['cancelLabel'][language] confOpts.submitLabel = snippetButtons['submitLabel'][language] confOpts.confirmText = snippetButtons['confirmText'][language] confOpts.cancelTrigger = snippetButtons['cancelTrigger'][language] snippet.confirmationOptions = confOpts snippet.smss = [sms] createAnchor.views = [askCreateView, snippet] return createAnchor
def finalSend(self, sms, language): commitCMD = DomainObjectCommit(self.refId) commitCMD.identifier = SmsSms() commitCMD.identifier.identifier = sms.identifier answer = self.getResponseForRequest(commitCMD) if ObjectIsCommand(answer, DomainObjectCommitCompleted): answer = DomainObjectCommitCompleted(answer) # update the sms object with current identifier and time stamp sms.identifier = answer.identifier # the timestamp should be timezone aware # we could use the pytz lib for that # get the timezone from the assistant # and supply it to pytz which we can # supply to now() sms.dateSent = datetime.datetime.now() # tell the user we sent the sms createAnchor = UIAddViews(self.refId) createAnchor.dialogPhase = createAnchor.DialogPhaseConfirmedValue # create a view to ask for the message askCreateView = UIAssistantUtteranceView() askCreateView.dialogIdentifier = "CreateSms#sentSMS" askCreateView.text = askCreateView.speakableText = random.choice( responses['sendSms'][language]) askCreateView.listenAfterSpeaking = False snippet = SmsSnippet() snippet.smss = [sms] createAnchor.views = [askCreateView, snippet] self.sendRequestWithoutAnswer(createAnchor) self.complete_request() else: self.say(random.choice(responses['sendSmsFail'][language])) self.complete_request()