Skip to content

Commit

Permalink
Reverting the changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
ChetanSharma-msft committed Dec 16, 2024
1 parent 0e3e2c1 commit ec4e5a1
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 259 deletions.
Original file line number Diff line number Diff line change
@@ -1,32 +1,23 @@
// <copyright file="AdapterWithErrorHandler.cs" company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
//
// Generated with Bot Builder V4 SDK Template for Visual Studio CoreBot v4.6.2
using Microsoft.Bot.Builder.Integration.AspNet.Core;
using Microsoft.Bot.Builder.TraceExtensions;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;

namespace Microsoft.Teams.Samples.HelloWorld.Web
{
using Microsoft.Bot.Builder.Integration.AspNet.Core;
using Microsoft.Bot.Builder.TraceExtensions;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;

/// <summary>
/// A custom BotFrameworkHttpAdapter with error handling capabilities.
/// </summary>
public class AdapterWithErrorHandler : BotFrameworkHttpAdapter

Check warning on line 12 in samples/app-hello-world/csharp/Microsoft.Teams.Samples.HelloWorld.Web/AdapterWithErrorHandler.cs

View workflow job for this annotation

GitHub Actions / Build All "app-hello-world" csharp

'BotFrameworkHttpAdapter' is obsolete: 'Use `CloudAdapter` instead.'

Check warning on line 12 in samples/app-hello-world/csharp/Microsoft.Teams.Samples.HelloWorld.Web/AdapterWithErrorHandler.cs

View workflow job for this annotation

GitHub Actions / Build All "app-hello-world" csharp

'BotFrameworkHttpAdapter' is obsolete: 'Use `CloudAdapter` instead.'
{
/// <summary>
/// Initializes a new instance of the <see cref="AdapterWithErrorHandler"/> class.
/// </summary>
/// <param name="configuration">The configuration for the bot.</param>
/// <param name="logger">The logger to use for logging errors.</param>
public AdapterWithErrorHandler(IConfiguration configuration, ILogger<BotFrameworkHttpAdapter> logger)

Check warning on line 14 in samples/app-hello-world/csharp/Microsoft.Teams.Samples.HelloWorld.Web/AdapterWithErrorHandler.cs

View workflow job for this annotation

GitHub Actions / Build All "app-hello-world" csharp

'BotFrameworkHttpAdapter' is obsolete: 'Use `CloudAdapter` instead.'

Check warning on line 14 in samples/app-hello-world/csharp/Microsoft.Teams.Samples.HelloWorld.Web/AdapterWithErrorHandler.cs

View workflow job for this annotation

GitHub Actions / Build All "app-hello-world" csharp

'BotFrameworkHttpAdapter' is obsolete: 'Use `CloudAdapter` instead.'
: base(configuration, logger)
{
this.OnTurnError = async (turnContext, exception) =>
OnTurnError = async (turnContext, exception) =>
{
// Log any leaked exception from the application.
logger.LogError(exception, "[OnTurnError] unhandled error : {Message}", exception.Message);
logger.LogError(exception, $"[OnTurnError] unhandled error : {exception.Message}");

// Uncomment below commented line for local debugging.
// await turnContext.SendActivityAsync($"Sorry, it looks like something went wrong. Exception Caught: {exception.Message}");
Expand All @@ -36,4 +27,4 @@ public AdapterWithErrorHandler(IConfiguration configuration, ILogger<BotFramewor
};
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,19 @@
// <copyright file="MessageExtension.cs" company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Schema;
using Microsoft.Bot.Builder.Teams;
using Microsoft.Bot.Schema.Teams;
using Newtonsoft.Json.Linq;
using System.Linq;
using System;
using System.Collections.Generic;
using Bogus;

namespace Microsoft.Teams.Samples.HelloWorld.Web
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Bogus;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Teams;
using Microsoft.Bot.Schema;
using Microsoft.Bot.Schema.Teams;
using Newtonsoft.Json.Linq;

/// <summary>
/// A bot that handles messaging extensions for Microsoft Teams.
/// </summary>
public class MessageExtension : TeamsActivityHandler
{
/// <summary>
/// Handles incoming message activities.
/// </summary>
/// <param name="turnContext">The context object for this turn.</param>
/// <param name="cancellationToken">A cancellation token for the task.</param>
/// <returns>A task that represents the work queued to execute.</returns>
protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
{
turnContext.Activity.RemoveRecipientMention();
Expand All @@ -36,17 +23,9 @@ protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivi
await turnContext.SendActivityAsync(MessageFactory.Text(replyText, replyText), cancellationToken);
}

/// <summary>
/// Handles messaging extension queries.
/// </summary>
/// <param name="turnContext">The context object for this turn.</param>
/// <param name="query">The query object for the messaging extension.</param>
/// <param name="cancellationToken">A cancellation token for the task.</param>
/// <returns>A task that represents the work queued to execute.</returns>
/// <exception cref="NotImplementedException">Thrown when the command ID is invalid.</exception>
protected override Task<MessagingExtensionResponse> OnTeamsMessagingExtensionQueryAsync(ITurnContext<IInvokeActivity> turnContext, MessagingExtensionQuery query, CancellationToken cancellationToken)
{
var title = string.Empty;
var title = "";
var titleParam = query.Parameters?.FirstOrDefault(p => p.Name == "cardTitle");
if (titleParam != null)
{
Expand All @@ -72,54 +51,41 @@ protected override Task<MessagingExtensionResponse> OnTeamsMessagingExtensionQue
{
AttachmentLayout = "list",
Type = "result",
Attachments = attachments.ToList(),
Attachments = attachments.ToList()
},
};
return Task.FromResult(result);
}

/// <summary>
/// Handles the selection of an item in a messaging extension.
/// </summary>
/// <param name="turnContext">The context object for this turn.</param>
/// <param name="query">The query object for the messaging extension.</param>
/// <param name="cancellationToken">A cancellation token for the task.</param>
/// <returns>A task that represents the work queued to execute.</returns>
protected override Task<MessagingExtensionResponse> OnTeamsMessagingExtensionSelectItemAsync(ITurnContext<IInvokeActivity> turnContext, JObject query, CancellationToken cancellationToken)
{
return Task.FromResult(new MessagingExtensionResponse
{
ComposeExtension = new MessagingExtensionResult
{
AttachmentLayout = "list",
Type = "result",
Attachments = new MessagingExtensionAttachment[]
{
new ThumbnailCard()
.ToAttachment()
.ToMessagingExtensionAttachment(),
},
},
});
}

/// <summary>
/// Creates a messaging extension attachment with a thumbnail card.
/// </summary>
/// <param name="title">The title for the card.</param>
/// <returns>A messaging extension attachment.</returns>
private static MessagingExtensionAttachment GetAttachment(string title)
{
var card = new ThumbnailCard
{
Title = !string.IsNullOrWhiteSpace(title) ? title : new Faker().Lorem.Sentence(),
Text = new Faker().Lorem.Paragraph(),
Images = new List<CardImage> { new CardImage("http://lorempixel.com/640/480?rand=" + DateTime.Now.Ticks.ToString()) },
Images = new List<CardImage> { new CardImage("http://lorempixel.com/640/480?rand=" + DateTime.Now.Ticks.ToString()) }
};

return card
.ToAttachment()
.ToMessagingExtensionAttachment();
}
protected override Task<MessagingExtensionResponse> OnTeamsMessagingExtensionSelectItemAsync(ITurnContext<IInvokeActivity> turnContext, JObject query, CancellationToken cancellationToken)
{
return Task.FromResult(new MessagingExtensionResponse
{
ComposeExtension = new MessagingExtensionResult
{
AttachmentLayout = "list",
Type = "result",
Attachments = new MessagingExtensionAttachment[]{
new ThumbnailCard()
.ToAttachment()
.ToMessagingExtensionAttachment()
}
},
});
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,48 +1,36 @@
// <copyright file="BotController.cs" company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>

// Licensed under the MIT License.
//
// Generated with Bot Builder V4 SDK Template for Visual Studio EchoBot v4.6.2
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Integration.AspNet.Core;

namespace Microsoft.Teams.Samples.HelloWorld.Web.Controllers
{
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Integration.AspNet.Core;

/// <summary>
/// This ASP Controller is created to handle a request. Dependency Injection will provide the Adapter and IBot
/// implementation at runtime. Multiple different IBot implementations running at different endpoints can be
/// achieved by specifying a more specific type for the bot constructor argument.
/// </summary>
// This ASP Controller is created to handle a request. Dependency Injection will provide the Adapter and IBot
// implementation at runtime. Multiple different IBot implementations running at different endpoints can be
// achieved by specifying a more specific type for the bot constructor argument.
[Route("api/messages")]
[ApiController]
public class BotController : ControllerBase
{
private readonly IBot bot;
private readonly IBotFrameworkHttpAdapter adapter;
private readonly IBotFrameworkHttpAdapter Adapter;
private readonly IBot Bot;

/// <summary>
/// Initializes a new instance of the <see cref="BotController"/> class.
/// </summary>
/// <param name="adapter">The bot framework HTTP adapter.</param>
/// <param name="bot">The bot instance.</param>
public BotController(IBotFrameworkHttpAdapter adapter, IBot bot)
{
this.adapter = adapter;
this.bot = bot;
Adapter = adapter;
Bot = bot;
}

/// <summary>
/// Handles the HTTP POST request.
/// </summary>
/// <returns>A task that represents the work queued to execute.</returns>
[HttpPost]
public async Task PostAsync()
{
// Delegate the processing of the HTTP POST to the adapter.
// The adapter will invoke the bot.
await this.adapter.ProcessAsync(this.Request, this.Response, this.bot);
await Adapter.ProcessAsync(Request, Response, Bot);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,65 +1,41 @@
// <copyright file="HomeController.cs" company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

namespace Microsoft.Teams.Samples.HelloWorld.Web.Controllers
{
using Microsoft.AspNetCore.Mvc;

/// <summary>
/// HomeController class to handle web requests for the home page and other routes.
/// </summary>
[Route("")]
public class HomeController : Controller
{
/// <summary>
/// Handles the default route and returns the Index view.
/// </summary>
/// <returns>The Index view.</returns>
[Route("")]
public ActionResult Index()
{
return this.View();
return View();
}

/// <summary>
/// Handles the /hello route and returns the Index view.
/// </summary>
/// <returns>The Index view.</returns>
[Route("hello")]
public ActionResult Hello()
{
return this.View("Index");
return View("Index");
}

/// <summary>
/// Handles the /first route and returns the First view.
/// </summary>
/// <returns>The First view.</returns>
[Route("first")]
public ActionResult First()
{
return this.View();
return View();
}

/// <summary>
/// Handles the /second route and returns the Second view.
/// </summary>
/// <returns>The Second view.</returns>
[Route("second")]
public ActionResult Second()
{
return this.View();
return View();
}

/// <summary>
/// Handles the /configure route and returns the Configure view.
/// </summary>
/// <returns>The Configure view.</returns>
[Route("configure")]
public ActionResult Configure()
{
return this.View();
return View();
}
}
}

This file was deleted.

Loading

0 comments on commit ec4e5a1

Please sign in to comment.