示例#1
0
        public async Task OnReceiveActivity(IBotContext context)
        {
            var msgActivity = context.Request.AsMessageActivity();

            if (msgActivity != null)
            {
                var conversationState = context.GetConversationState <EchoState>() ?? new EchoState();

                conversationState.TurnNumber++;

                // calculate something for us to return
                int length = (msgActivity.Text ?? string.Empty).Length;

                // simulate calling a dependent service that was injected
                await _myService.DoSomethingAsync();

                // return our reply to the user
                context.Reply($"[{conversationState.TurnNumber}] You sent {msgActivity.Text} which was {length} characters");
            }

            var convUpdateActivity = context.Request.AsConversationUpdateActivity();

            if (convUpdateActivity != null)
            {
                foreach (var newMember in convUpdateActivity.MembersAdded)
                {
                    if (newMember.Id != convUpdateActivity.Recipient.Id)
                    {
                        context.Reply("Hello and welcome to the echo bot.");
                    }
                }
            }
        }
        public static async Task <IActionResult> InjectMyServiceWithBinding(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req,
            [DependencyInjection(typeof(IMyService))] IMyService myService,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            string name = req.Query["name"];

            var responseMessage = await myService.DoSomethingAsync(name);

            return(responseMessage != null
                ? (ActionResult) new OkObjectResult(responseMessage)
                : new BadRequestObjectResult("Please pass a name on the query string or in the request body"));
        }