Difficulty accessing messages in an existing conversation in Microsoft Bot Framework - c#

I'm trying to build a separate app - basically a daemon running on my intranet - that can connect to a Bot Connector app and access an existing conversation between a user and the bot.
To start at this, I'm using the DirectLine NuGet package, and then searching for existing messages with the conversationId found in a conversation I've started with the bot via the emulator.
For example, I fired up the emulator, and got the conversationId "8a684db8". Over in my console app, I've got the following relevant code:
var uri = new Uri("https://directline.botframework.com");
DirectLineClientCredentials creds = new DirectLineClientCredentials(secret); //lot into the bot framework
DirectLineClient client = new DirectLineClient(uri, creds); //connect the client
Conversations convs = new Conversations(client); //get the list of conversations belonging to the bot? Or does this start a new collection of conversations?
var existing_conv_messages = convs.GetMessages(convo_id);
Now, when I try to run it, I'm getting a "Not Found" error on the last line where I tried to find existing messages.
Anyone have a solution here?

Conversations sent to the emulator don't get sent to the Direct Line API. For messages to be viewable in Direct Line, they need to be sent through the online, running Connector and Direct Line services.

Related

Unable to make bot reply in thread on Slack

I have a single-tenant bot, built on Bot.Builder 18.1 that is currently running in a Slack channel. My challenge is that I would like the bot to always reply in a thread, when possible, so:
If already in a thread, reply in that thread
If on a channel, create a new thread and reply there
As far as I understand, the way to achieve this is to set the property thread_ts to the value of the ts property. I can get this value, however all attempts to set thread_ts still only give me replies in the channel directly, and not in a new thread, as expected. My last failed attempt was setting it on the reply message:
string? thread_ts = null;
if (slackChannelData is not null)
{
thread_ts = slackChannelData?.SlackMessage?._event?.ts;
}
reply.Conversation.Properties[nameof(thread_ts)] = thread_ts;
And yes, I do get the ts value out of that :)
I also attempted to use the Slack Adapter, however it fails for som authentication reasons, even though I've set it's required configuration values (SlackBotToken, SlackVerificationToken and SlackClientSigningSecret). I cannot get the Slack Adapter to get past the authentication. The slack adapter follows the latest example on GitHub, and targets the community.adapters.slack version 4.13.5
So my question is:
Does anyone know if it is possible to use the Bot Framework and a slack channel to reply in thread in Slack given my want above?

Is there a way to send Cloud Messages or Push Notifications to a Flutter App from C#?

For my use case, a user from C# WinForm desktop application generates some data (creates a new document in a collection named "Requests" in Firestore). What I want is that whenever a new document is created/added in the Requests collection, a notification is sent to the Flutter app. I am looking for some guidelines for a workaround regarding this using C#.
I assume that you have already connected your C# software with firebase as backend. If that is the case then:
1- First connect your flutter app to firebase.
Follow this link to do so: Connect flutter app to firebase
2- Use this link to learn and create your first cloud function on firebase.
Create first cloud function from flutter app terminal
3- Now you are in the position to create a cloud function with which a notification will be generated to the device you want on the creation of document in the request collection.
4- Deploy this function on your firebase to send notification to your required device.
exports.sendFirstNotification =
functions.firestore.document('/Requests/{documentId}')
.onCreate(async (snap, context) => {
var name = "Bilal Saeed";
var myDeviceToken = snap.data().fcmToken;
// You need this token for push notification on a device.
// Each device has its own token.
// Access it in this function.
//If you are working on C# software then create your token from flutter app
//and save it on firestore. And access that token here and save it in myDeviceToken variable.
// Currently in this function its assumed that, the newly document created //in your Request collection contains the device token which is being //assigned to myDeviceToken variable.
await admin.messaging().send({
token: myDeviceToken,
notification: {
title: `Hi, you received first notification by the help of ${name}`,
body: " Upvote his answer if he really helped you!"
},
}).then(value => {
functions.logger.log("First notification sent to the device");
}).catch((e) =>{
functions.logger.log(e.toString());
});
});
Use this command from terminal to deploy your this function.
firebase deploy --only functions:sendFirstNotification
Now create the document from your C# software and you will get the notification on your flutter app mobile device on the creation of document in Requests Collection. Congrats!

Discord.NET Trying to get SocketUser as SocketGuildUser returning null

I am working on a C# Discord.Net bot, and have come across an issue I thought I had previously resolved.
I need to get the user mentioned in the message as a 'SocketGuildUser'. This works perfectly fine when I attempt it on my own user. However, it wasn't working on my friend's user. While it could get a 'SocketUnknownUser', it failed to get a 'SocketGuildUser', just returning null. After I removed a certain role from them, the bot worked completely fine for a couple of days. However, all of sudden, it has now stopped being able to get a 'SocketGuildUser' from my friend's user, with no changes to the relevant code.
Here is the relevant code:
var userToModCheck = message.MentionedUsers.ElementAt(0);
var userToMod = message.MentionedUsers.ElementAt(0) as SocketGuildUser;
userToModCheck returns the correct username and user ID, but as a SocketUnknownUser. userToMod returns null.
So far, I have tried:
Checking the bot 'Privileged Gateway Intents' permissions in the Discord developer portal
Using a separate function(Context.Guild.GetUser) to get the SocketGuildUser using the user ID
Changing roles
Restarting both computers
Searching the internet
Edit: There are no issues when the mentioned user is online and has the online status. Very strange.
Edit 2: Switching 'AlwaysDownloadUsers' to true does not resolve the issue.
'DiscordSocketConfig' wasn't configured properly. Firstly, make sure all 'Priveleged Gateway Intents' are enabled in the Discord Developer Portal. (Application > Bot).
Change 'AlwaysDownloadUsers' to true, and 'GatewayIntents' to all, then apply it to the client:
var config = new DiscordSocketConfig{ AlwaysDownloadUsers = true, GatewatIntents = GatewayIntents.All };
_client = new DiscordSocketClient{config};
The bot then works properly.

Connect to offline directline routing to local echo bot based on Microsoft Bot Framework

I want to create a Line messaging bot using API wrapper provided by pierre3 hosted on local environment.
Line Messaging Service ~~POST~~> WebApi.Net ~X-> Offline-Directline ---> Echobot (Bot Framework)
I am using the node package "offline-directline" which should enable to route
messages to the local bot, created from Echobot template bundled in
Microsoft BotFramework Extension.
This is the text printed on the node terminal:
Offline-Directline: Listening for messages from client on http://127.0.0.1:3000
Routing messages to bot on http://localhost:3978/api/messages
So far, my webapi is able to receive the request from Line Messenging Service.
The problem is I don't know how to connect from webapi to the offline-directline.
DirectLineClient doesnt throw exception, but
whenever the webapi execute StartConversationAsync(), the conversation always return null.
I can confirm my Echobot is working, because I can interact with it using Bot Framework Emulator.
var uri = new Uri("http://localhost:3978/api/messages");
var cred = new DirectLineClientCredentials(null, http://localhost:3000/directline");
this.dlClient = new DirectLineClient(uri, cred);
var conversation = await dlClient.Conversations.StartConversationAsync();
//this is always return null
I expect when I send the text "hello world" via Line Messenger,
the bot will respond with the same text "hello world" on Line Messenger.
And for extra information, I am not sure this is relevant or not:
the Line Messaging Api Wrapper require to use Azure blob storage.
I don't have a online Azure Blob Storage, instead I am using Storage Emulator and set the connection string to "UseDevelopmentStorage=true".
I assume this is working because I have checked the instance of CloudBlobClient is not null and it contains the valid uri pointing to local emulator.
--
I have stuck on this for many hours yet having no clue.
Any help would be much appreciated.

Read email content and move items between folders with Exchange 2010 and c#

I’m working on an application that must read the email content and move emails from one folder to another, these are the only two features that it must support. The mail server is Exchange 2010 and I have enough privileges to access the mailbox.
I’ve been seeing some posts about EWS Managed Code but I’m certainly lost in all this information. Can you shed some light on this and advise about the best approach to accomplish it?
Ps. Using VS 2015 and .net framework 4.5
Update: find below a quick test using the EWS Manage API
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013);
//This will accept all certificates, regardless of why they are invalid
ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true;
service.Credentials = new WebCredentials("Administrator", "mypassword", "myexchangeserver.com");
service.Url = new Uri("https://myexchangeserver.com/EWS/Exchange.asmx");
EmailMessage email = new EmailMessage(service);
email.ToRecipients.Add("userid#myexchangeserver.com");
email.Subject = String.Format("HelloWorld at {0}", DateTime.Now);
email.Body = new MessageBody("This is the first email I've sent by using the EWS Managed API.");
email.Send();
I’m working on an application that must read the email content and move emails from one folder
Okay so you will need to use a Exchange Mailbox API to access Mailbox content, on Exchange 2010 the available API's that you could use to move a Message between folders would be MAPI (via the Outlook Object Model or Thirdparty library like Redemption) or Exchange Web Services (EWS). (other API's like POP,IMAP and Activesync would also work but are much harder to use).
To work out which is the best API to use you need to consider where your application is going to run eg if you building an code that run within outlook then using the OOM. If you building an application that is going to run on the server then use EWS.
I’ve been seeing some posts about EWS Managed Code but I’m certainly lost in all this information.
If your going to write and EWS app then using the Managed API is the best way to go, the best place is to jump into write some actual code eg start with
https://msdn.microsoft.com/en-us/library/office/dn567668(v=exchg.150).aspx
then try
https://msdn.microsoft.com/en-us/library/office/dn600291(v=exchg.150).aspx
Cheers
Glen

Categories