Skip to main content

Notifications

Copilot Studio - General
Unanswered

How can i get on Conversation start message in C#

(0) ShareShare
ReportReport
Posted on by 4

Hi Team,

I would like to receive the initial conversation start message created in Copilot Studio in C#. We use the DirectLineClient object to get the default message, but I'm not getting the conversation start message with the code below. The client.Conversations.GetActivitiesAsync(conversationId, watermark) call always returns null.

// Initialize Direct Line client
var client = new DirectLineClient(directLineSecret);
// Start a new conversation
var conversation = await client.Conversations.StartConversationAsync();

Console.WriteLine($"CoPilot ConversationId: {conversation.ConversationId}");

static async Task GetInitialBotMessageAsync(DirectLineClient client, string conversationId)
{
string watermark = null;
// Poll for messages, assuming the bot sends a message at conversation start
while (true)
{
var response = await client.Conversations.GetActivitiesAsync(conversationId, watermark);
watermark = response.Watermark;
foreach (var activity in response.Activities)
{
if (activity.From.Id == "bot")
{
Console.WriteLine($"Bot (Initial Message): {activity.Text}");
return; // Exit after getting the initial message
}
}
await Task.Delay(1000); // Wait before polling again
}
}

// Ysend a message to the bot if needed
var userMessage = new Activity
{
From = new ChannelAccount("user1"),
Text = "Hello, how can I help?",
Type = ActivityTypes.Message
};
await client.Conversations.PostActivityAsync(conversationId, userMessage);

// We are getting a success response for the message what we sent
var response = await client.Conversations.GetActivitiesAsync(conversationId, watermark);
Categories:
  • CU14081638-0 Profile Picture
    CU14081638-0 4 on at
    How can i get on Conversation start message in C#
    I would like to retrieve the default start conversation message from  that we created in Copilot Studio UI . We created a trigger 'On Conversation Start' on a topic with a message. How do I get this message using client.Conversations.GetActivitiesAsync .
  • peterswimm Profile Picture
    peterswimm on at
    How can i get on Conversation start message in C#
    Can you explain more about what you are doing? Are you creating a custom channel? Have you seen: https://learn.microsoft.com/en-us/microsoft-copilot-studio/publication-connect-bot-to-azure-bot-service-channels#sample-code-example

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,343

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,703

Leaderboard