如何在Alexa中以编程方式清除自定义插槽值?

时间:2018-01-04 07:09:47

标签: javascript alexa alexa-skills-kit alexa-skill alexa-slot

我有一个Alexa技能,需要以编程方式覆盖用户给出的值。

我尝试使值无效,然后将其作为“更新的Intent”传递。

this.event.request.intent.userPrompt.value = null;
var updatedIntent = this.event.request.intent;
this.emit(':elicitSlot', 'userPrompt',"Say something","Say something", updatedIntent);

但是,输入JSON显示以前的值。有解决方案吗?

2 个答案:

答案 0 :(得分:2)

 WebElement  elem = driver.findElement(By.id("summaryTable"));

    List<WebElement> lists = elem.findElements(By.tagName("th"));

    for(WebElement el : lists){

        WebElement element = el.findElement(By.tagName("a"));

        String  str = element.getAttribute("innerHTML");
        System.out.println(str);

    }

如果您有自定义插槽类型的插槽,则还必须

delete this.event.request.intent.slots.<slotname>.value;
var updatedIntent = this event.request.intent;
this.emit(':elicitSlot', <slotname>,"Say something","Say something", updatedIntent);

答案 1 :(得分:0)

对于版本V2,您应该以这种方式(据我所知)更新意图

$strhtml='
    <html>
    <head>
        <title>duff html</title>
    </head>
    <body>
    <!--
        first of too many
    -->
    <!--Array
            (
                [0] => Pagedale
                [1] => 3,304.
                [2] => 1.19
                [3] => $28,480
                [4] => 93.43%
                [5] => 22.40%
                [6] => 0.2640
                [7] => 0.3410
                [8] => 0.0000
                [9] => 0.3500
                [10] => $189,823
                [11] => 6.83%
                [12] => 8.363%
                [13] => $1,090,378
                [14] => 39.25%
                [15] => 1
                [16] => $2,434,084.00
                [17] => $2,778,093
                [18] => $2,540,416
                [19] => Sales Tax
                [20] => $1,090,378
                [21] => Utility Tax
                [22] => $471,471
                [23] => Court Fines/Fees
                [24] => $351,583
                [25] => Parks & Recreation
                [26] => $475,127
                [27] => Police
                [28] => $185,013
                [29] => TIF Match
                [30] => $60,153
                [31] => $47,417
                [32] => 7
                [33] => Pagedale PD
                [34] => 17
                [35] => Pagedale
                [36] => 12.66%
                [37] => $90,758
                [38] => $351,583
                [39] => 1420 Ferguson Ave
                [40] => Pagedale
                [41] => MO
                [42] => 63133
                [43] => 314-726-1200
                [44] => http://www.cityofpagedale.com
                [45] => M-F (9-5)
                [46] => The Board of Aldermen meet on the second Thursday of each month at 7:30pm
                [47] => 1420 Ferguson Auditorium
                [48] => 1
            )
            -->
                <div>Hello world </div>

                <!-- last comment -->
                <div> Last div </div>
            </body>
           </html>';


    $dom=new DOMDocument;
    $dom->loadHTML( $strhtml );
    $xp=new DOMXPath( $dom );
    $col=$xp->query('/html/body/comment()');

    if( $col && $col->length > 0 ){
        $comments=[];
        foreach( $col as $comment ){
            $comments[]=$comment->nodeValue;
        }
        printf('<pre>%s</pre>',print_r($comments,true));
    }

Array ( [0] => first of too many [1] => Array ( [0] => Pagedale [1] => 3,304. [2] => 1.19 [3] => $28,480 [4] => 93.43% [5] => 22.40% [6] => 0.2640 [7] => 0.3410 [8] => 0.0000 [9] => 0.3500 [10] => $189,823 [11] => 6.83% [12] => 8.363% [13] => $1,090,378 [14] => 39.25% [15] => 1 [16] => $2,434,084.00 [17] => $2,778,093 [18] => $2,540,416 [19] => Sales Tax [20] => $1,090,378 [21] => Utility Tax [22] => $471,471 [23] => Court Fines/Fees [24] => $351,583 [25] => Parks & Recreation [26] => $475,127 [27] => Police [28] => $185,013 [29] => TIF Match [30] => $60,153 [31] => $47,417 [32] => 7 [33] => Pagedale PD [34] => 17 [35] => Pagedale [36] => 12.66% [37] => $90,758 [38] => $351,583 [39] => 1420 Ferguson Ave [40] => Pagedale [41] => MO [42] => 63133 [43] => 314-726-1200 [44] => http://www.cityofpagedale.com [45] => M-F (9-5) [46] => The Board of Aldermen meet on the second Thursday of each month at 7:30pm [47] => 1420 Ferguson Auditorium [48] => 1 ) [2] => last comment ) 应该是可以设置新广告位值的对象,例如:

 handlerInput.responseBuilder
    .addDelegateDirective(newIntent)
    .getResponse();