Skip to content

Commit

Permalink
Merge pull request #1516 from OfficeDev/v-pakoshti/sample_fixes
Browse files Browse the repository at this point in the history
Fixed the samples
  • Loading branch information
Harikrishnan-MSFT authored Jan 6, 2025
2 parents 4b71e4c + 41a17bd commit 8fdc650
Show file tree
Hide file tree
Showing 11 changed files with 252 additions and 156 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ await stepContext.BeginDialogAsync(
else if (command == DialogMatches.MultiDialog2Match)
{
return await stepContext.BeginDialogAsync(
nameof(MultiDialog2));
nameof(ThumbnailcardDialog));
}
else if (command == DialogMatches.FecthLastExecutedDialogMatch)
{
Expand Down
24 changes: 16 additions & 8 deletions samples/bot-tag-mention/csharp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ This sample app demonstrates the use of tag mention funtionality in teams scope

The simplest way to run this sample in Teams is to use Teams Toolkit for Visual Studio.

1.Install Visual Studio 2022 Version 17.10 Preview 4 or higher Visual Studio
2.Install Teams Toolkit for Visual Studio Teams Toolkit extension
3.In the debug dropdown menu of Visual Studio, select Dev Tunnels > Create A Tunnel (set authentication type to Public) or select an existing public dev tunnel.
4.In the debug dropdown menu of Visual Studio, select default startup project > Microsoft Teams (browser)
5.In Visual Studio, right-click your TeamsApp project and Select Teams Toolkit > Prepare Teams App Dependencies
6.Using the extension, sign in with your Microsoft 365 account where you have permissions to upload custom apps.
7.Select Debug > Start Debugging or F5 to run the menu in Visual Studio.
8.In the browser that launches, select the Add button to install the app to Teams.
1. Install Visual Studio 2022 Version 17.10 Preview 4 or higher Visual Studio
2. Install Teams Toolkit for Visual Studio Teams Toolkit extension
3. In the debug dropdown menu of Visual Studio, select Dev Tunnels > Create A Tunnel (set authentication type to Public) or select an existing public dev tunnel.
4. In the debug dropdown menu of Visual Studio, select default startup project > Microsoft Teams (browser)
5. In Visual Studio, right-click your TeamsApp project and Select Teams Toolkit > Prepare Teams App Dependencies
6. Using the extension, sign in with your Microsoft 365 account where you have permissions to upload custom apps.
7. Select Debug > Start Debugging or F5 to run the menu in Visual Studio.
8. In the browser that launches, select the Add button to install the app to Teams.

If you do not have permission to upload custom apps (sideloading), Teams Toolkit will recommend creating and using a Microsoft 365 Developer Program account - a free program to get your own dev environment sandbox that includes Teams.

Expand Down Expand Up @@ -172,6 +172,14 @@ You can interact with this bot in Teams by sending it a message, or selecting a

**Team channel Scope**

**Create tags within the team channel**
To create tags in Microsoft Teams, follow these steps:

1. Select Teams on the left side of the app and choose the team you want to create tags for.
2. Click the "More options" button (three dots) next to the team name and select "Manage tags".
3. Click "Create tag" and provide a name, description, and assign team members to the tag .


1. **Show Welcome**
- **Result:** The bot will send the welcome card for you to interact with necessary commands
- **Valid Scopes:** team chat
Expand Down
7 changes: 7 additions & 0 deletions samples/bot-tag-mention/nodejs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,13 @@ You can interact with this bot in Teams by sending it a message, or selecting a
**Team channel Scope**
**Create tags within the team channel**
To create tags in Microsoft Teams, follow these steps:
1. Select Teams on the left side of the app and choose the team you want to create tags for.
2. Click the "More options" button (three dots) next to the team name and select "Manage tags".
3. Click "Create tag" and provide a name, description, and assign team members to the tag.
1. **Show Welcome**
- **Result:** The bot will send the welcome card for you to interact with necessary commands
- **Valid Scopes:** team chat
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using AdaptiveCards;
using AdaptiveCards;
using Microsoft.Extensions.Configuration;
using Microsoft.Graph;
using Microsoft.Graph.Auth;
Expand Down Expand Up @@ -38,14 +38,28 @@ public async Task<ChatMessage> CreateChatMessageForChannel(TaskDetails taskDetai
chatMessage.HostedContents = chatMessageHostedContentsCollectionPage;
try
{
var channelMessage = await graphClientChat.Teams[taskDetails.teamId].Channels[taskDetails.channelId].Messages
.Request()
.AddAsync(chatMessage);
return channelMessage;
// First, get the list of channels to find the default channel ID
var channels = await graphClientChat.Teams[taskDetails.teamId].Channels
.Request()
.GetAsync();

// Assuming "General" is the name of the default channel
var defaultChannel = channels.CurrentPage.FirstOrDefault(c => c.DisplayName.Equals("General", StringComparison.OrdinalIgnoreCase));

if (defaultChannel != null)
{
// Add the message to the default channel
var createdMessage = await graphClientChat.Teams[taskDetails.teamId].Channels[defaultChannel.Id].Messages
.Request()
.AddAsync(chatMessage);

// Return the created message
return createdMessage;
}
}
catch(Exception e)
catch (ServiceException ex)
{
Console.WriteLine(e);
Console.WriteLine($"Error adding message: {ex.Message}");
}
return null;
}
Expand All @@ -56,103 +70,120 @@ public async Task<ChatMessage> CreateChannelMessageAdaptiveCard(TaskDetails task
var Card = new AdaptiveCard(new AdaptiveSchemaVersion("1.0"))
{
Body = new List<AdaptiveElement>()
{
new AdaptiveTextBlock()
{
Text="Here is Your Reservation Details:",
Weight = AdaptiveTextWeight.Bolder,
Size = AdaptiveTextSize.Large,
Id="taskDetails"
},
new AdaptiveTextBlock()
{
Text=taskDetails.reservationId,
Weight = AdaptiveTextWeight.Lighter,
Size = AdaptiveTextSize.Medium,
Id="taskTitle"
},
new AdaptiveTextBlock()
{
Text=taskDetails.DeployementTitle,
Weight = AdaptiveTextWeight.Lighter,
Size = AdaptiveTextSize.Medium,
Id="taskdesc"
},
new AdaptiveTextBlock()
{
Text=taskDetails.currentSlot,
Weight = AdaptiveTextWeight.Lighter,
Size = AdaptiveTextSize.Medium,
Id="taskslot"
}
}

{
new AdaptiveTextBlock()
{
Text = "Here is Your Reservation Details:",
Weight = AdaptiveTextWeight.Bolder,
Size = AdaptiveTextSize.Large,
Id = "taskDetails"
},
new AdaptiveTextBlock()
{
Text = taskDetails.reservationId,
Weight = AdaptiveTextWeight.Lighter,
Size = AdaptiveTextSize.Medium,
Id = "taskTitle"
},
new AdaptiveTextBlock()
{
Text = taskDetails.DeployementTitle,
Weight = AdaptiveTextWeight.Lighter,
Size = AdaptiveTextSize.Medium,
Id = "taskdesc"
},
new AdaptiveTextBlock()
{
Text = taskDetails.currentSlot,
Weight = AdaptiveTextWeight.Lighter,
Size = AdaptiveTextSize.Medium,
Id = "taskslot"
}
}
};


var chatMessage = new ChatMessage
{
Subject = "Reservation Activtity:",
Subject = "Reservation Activity:",
Body = new ItemBody
{
ContentType = BodyType.Html,
Content = "<attachment id=\"74d20c7f34aa4a7fb74e2b30004247c5\"></attachment>"
},
Attachments = new List<ChatMessageAttachment>()
{
new ChatMessageAttachment
{
Id = "74d20c7f34aa4a7fb74e2b30004247c5",
ContentType = "application/vnd.microsoft.card.adaptive",
ContentUrl = null,
Content = JsonConvert.SerializeObject(Card),
Name = null,
ThumbnailUrl = null
}
}
Attachments = new List<ChatMessageAttachment>
{
new ChatMessageAttachment
{
Id = "74d20c7f34aa4a7fb74e2b30004247c5",
ContentType = "application/vnd.microsoft.card.adaptive",
ContentUrl = null,
Content = JsonConvert.SerializeObject(Card),
Name = null,
ThumbnailUrl = null
}
}
};

chatMessage.HostedContents = chatMessageHostedContentsCollectionPage;
var getChannelMessage = await graphClientChat.Teams[taskDetails.teamId].Channels[taskDetails.channelId].Messages
try
{
// First, get the list of channels to find the default channel ID
var channels = await graphClientChat.Teams[taskDetails.teamId].Channels
.Request()
.AddAsync(chatMessage);
return getChannelMessage;
.GetAsync();

// Assuming "General" is the name of the default channel
var defaultChannel = channels.CurrentPage.FirstOrDefault(c => c.DisplayName.Equals("General", StringComparison.OrdinalIgnoreCase));

if (defaultChannel != null)
{
// Add the message to the default channel
var createdMessage = await graphClientChat.Teams[taskDetails.teamId].Channels[defaultChannel.Id].Messages
.Request()
.AddAsync(chatMessage);

// Return the created message
return createdMessage;
}
}
catch (ServiceException ex)
{
Console.WriteLine($"Error adding message: {ex.Message}");
}
return null;
}

public async Task<ChatMessage> CreatePendingFinanceRequestCard(TaskDetails taskDetails, string accessToken)
public async Task<ChatMessage> CreatePendingFinanceRequestCard(TaskDetails taskDetails, string accessToken)
{
GraphServiceClient graphClientChat= SimpleGraphClient.GetGraphClient(accessToken);
GraphServiceClient graphClientChat = SimpleGraphClient.GetGraphClient(accessToken);
var Card = new AdaptiveCard(new AdaptiveSchemaVersion("1.0"))
{
Body = new List<AdaptiveElement>()
{
new AdaptiveTextBlock()
{
Text="Here is Your Task Details in Teams",
Weight = AdaptiveTextWeight.Bolder,
Size = AdaptiveTextSize.Large,
Id="taskDetails"
},
new AdaptiveTextBlock()
{
Text=taskDetails.title,
Weight = AdaptiveTextWeight.Lighter,
Size = AdaptiveTextSize.Medium,
Id="taskTitle"
},
new AdaptiveTextBlock()
{
Text=taskDetails.description,
Weight = AdaptiveTextWeight.Lighter,
Size = AdaptiveTextSize.Medium,
Id="taskdesc"
},
}

{
new AdaptiveTextBlock()
{
Text = "Here is Your Task Details in Teams",
Weight = AdaptiveTextWeight.Bolder,
Size = AdaptiveTextSize.Large,
Id = "taskDetails"
},
new AdaptiveTextBlock()
{
Text = taskDetails.title,
Weight = AdaptiveTextWeight.Lighter,
Size = AdaptiveTextSize.Medium,
Id = "taskTitle"
},
new AdaptiveTextBlock()
{
Text = taskDetails.description,
Weight = AdaptiveTextWeight.Lighter,
Size = AdaptiveTextSize.Medium,
Id = "taskdesc"
},
}
};


var chatMessage = new ChatMessage
{
Subject = null,
Expand All @@ -162,26 +193,50 @@ public async Task<ChatMessage> CreatePendingFinanceRequestCard(TaskDetails task
Content = "<attachment id=\"74d20c7f34aa4a7fb74e2b30004247c5\"></attachment>"
},
Attachments = new List<ChatMessageAttachment>()
{
new ChatMessageAttachment
{
Id = "74d20c7f34aa4a7fb74e2b30004247c5",
ContentType = "application/vnd.microsoft.card.adaptive",
ContentUrl = null,
Content = JsonConvert.SerializeObject(Card),
Name = null,
ThumbnailUrl = null
}
}
{
new ChatMessageAttachment
{
Id = "74d20c7f34aa4a7fb74e2b30004247c5",
ContentType = "application/vnd.microsoft.card.adaptive",
ContentUrl = null,
Content = JsonConvert.SerializeObject(Card),
Name = null,
ThumbnailUrl = null
}
}
};

chatMessage.HostedContents = chatMessageHostedContentsCollectionPage;
var getChannelMessage = await graphClientChat.Teams[taskDetails.teamId].Channels[taskDetails.channelId].Messages

try
{
// First, get the list of channels to find the default channel ID
var channels = await graphClientChat.Teams[taskDetails.teamId].Channels
.Request()
.AddAsync(chatMessage);
return getChannelMessage;
.GetAsync();

// Assuming "General" is the name of the default channel
var defaultChannel = channels.CurrentPage.FirstOrDefault(c => c.DisplayName.Equals("General", StringComparison.OrdinalIgnoreCase));

if (defaultChannel != null)
{
// Add the message to the default channel
var createdMessage = await graphClientChat.Teams[taskDetails.teamId].Channels[defaultChannel.Id].Messages
.Request()
.AddAsync(chatMessage);

// Return the created message
return createdMessage;
}
}
catch (ServiceException ex)
{
Console.WriteLine($"Error adding message: {ex.Message}");
}
return null;
}


public async Task<ChatMessage> CreateGroupChatMessage(TaskDetails taskDetails, string accessToken)
{
var graphClientChat = SimpleGraphClient.GetGraphClient(accessToken);
Expand Down
Loading

0 comments on commit 8fdc650

Please sign in to comment.