简体   繁体   English

如何使用异步功能修复“意外令牌”错误

[英]How to fix 'Unexpected Token' error with async function

I am developing a web app bot on azure (v3) and I am using async methods but I can't seem to solve an issue which is SyntaxError: Unexpected token function. 我正在azure(v3)上开发一个Web应用程序机器人,并且正在使用异步方法,但似乎无法解决SyntaxError:意外令牌功能这一问题。

I've tried updating my nodeJS from 6.9.4 to 8.9 but that didn't work. 我尝试将nodeJS从6.9.4更新到8.9,但这没有用。 I also ran npm i -g azure-functions-core-tools@core but still nothing. 我还运行了npm i -g azure-functions-core-tools @ core,但还是没有。

class OAuthHelpers {
/**
 * Enable the user to schedule meeting and send an email attachment via the bot.
 * @param {TurnContext} turnContext 
 * @param {TokenResponse} tokenResponse 
 * @param {*} emailAddress The email address of the recipient
 */

async function createevent(turnContext, tokenResponse, emailAddress) {
    if (!turnContext) {
        throw new Error('OAuthHelpers.createevent(): `turnContext` cannot be undefined.');
    }
    if (!tokenResponse) {
        throw new Error('OAuthHelpers.createevent(): `tokenResponse` cannot be undefined.');
    }


    var client = new SimpleGraphClient(tokenResponse.token);

    // Calls the Graph API with the subject and content message...
    await client.createevent(
        emailAddress,
        `Lunch`,
        `I will be taking everyone to lunch as a reward for your hardwork.`
    );

    // Success message...
    await turnContext.sendActivity(`Success! I have scheduled a meeting with you and ${ emailAddress } have created an event on each of their calendars.`);
    } 

I want the bot to run normally but it can't because azure can't detect the async function for some reason. 我希望机器人能够正常运行,但不能运行,因为azure由于某种原因无法检测到异步功能。 Any help is appreciated 任何帮助表示赞赏

The OAuthHelpers class requires 'simple-graph-client' which houses all of the methods you are looking to utilize. OAuthHelpers类需要使用“ simple-graph-client”,其中包含您要使用的所有方法。 In the original sample your code draws from, BotBuilder-Sample 24.bot-authentication-msgraph , if you navigate to the simple-graph-client.js file, you will see the methods called (ie sendMail, getRecentMail, getMe, and getManager) in the OAuthHelpers.js file. 在您的代码所引用的原始示例BotBuilder-Sample 24.bot-authentication-msgraph中 ,如果导航到simple-graph-client.js文件,则将看到称为的方法(即sendMail,getRecentMail,getMe和getManager )在OAuthHelpers.js文件中。

If you haven't already, you will need to include a method for creating an event. 如果还没有,则需要包括一个用于创建事件的方法。 This, in turn is called from the OAuthHelpers.js file as part of the bot dialog. 继而从bot对话框的OAuthHelpers.js文件中调用该文件。

It's hard to know what is what without more code, but my guess is the token is being passed into your createevent method but, as the method (likely) doesn't exist as a graph api call, it doesn't know what to do with it. 没有更多的代码,很难知道什么是什么,但是我猜是令牌被传递到您的createevent方法中,但是由于该方法(可能)不作为图形api调用存在,因此它不知道该怎么做用它。

Check out the following links for guidance: 请查看以下链接以获得指导:

  • MS Graph sample showing a GET call for top 3 calendar events MS Graph 示例显示了对前3个日历事件的GET调用
  • MS Graph unit test example , but demonstrates an event POST MS Graph单元测试示例 ,但演示了一个事件POST
  • API reference for creating an event 用于创建事件的API 参考
  • Add'l info on creating recurring events...might prove useful 用户互动,增加信息创建重复事件......可能证明是有用的

Hope of help! 希望有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM