How to Trigger End of Conversation in Botframework V4? - c#

I'm trying to get the condition (turnContext.Activity.Type == ActivityTypes.EndOfConversation) triggered in OnTurnAsync method so that I can perform some cleanup/summary for chat etc. How can I achieve that?
I've tried CancelAllDialogsAsync() and EndDialogsAsync() but both aren't going to end the chat. FYI, I'm using bot-emulator 4.2.1 and do not have other channel to test.
When CancelAllDialogsAsync() is called, my conversation will go back to the very first dialog (which is list of suggestion). While EndDialogsAsync("End",cancellationToken) just stop the conversation but did not trigger the EndOfConversation Activity type.

You can't do this from the Teams client - Teams doesn't use endOfConversation at all, and all messages between a user and your bot are forever included in the same conversation thread.
If you're using some variant of Direct-Line (e.g. botframework-webchat, or the C# Direct-Line SDK) then you can rig up a button or other element to send an "endOfConversation" activity

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?

Discord.NET Guild.DefaultChannel does not work

I am coding a discord bot, and I want it to send a message to a server default channel whenever the bot joins a new server.
Here is my code
client.JoinedGuild += async guild =>
{
var channel = guild.DefaultChannel;
await channel.SendMessageAsync("test");
};
The error occurs on channel.SendMessageAsync, and when I debugged the program, it keeps showing that channel is null even though I do have a default channel in my server.
A discord update months ago removed defaultChannel property. Which means that servers now do not need to have a default channel at all.
(You can even delete all channel in your server!)
Which also means Guild.DefaultChannel property will not work as intended anymore.
(Correct me if I am wrong, but if a server still has a #general channel, the property will work as intended.)
Discord.NET v2+ have a working DefaultChannel property. (It uses its own set of algorithm to determine which would be the default channel for the guild.)
The source code for the algorithm is here. (Line 66-69)
Looking at the algorithm, you may want to be slightly cautious about using it, if your bot have permission to send messages everywhere, the DefaultChannel property would simply be the first channel in the server's channel list.
(And it would be bad news if that was a readme channel)

Discord Bot command cooldown

I'm trying to add a cooldown on on my ~hunt command for my Discord Bot. Which only can be used once in 5 minutes. I've tried different ways to program it but it doesn't work for me. Does anyone know a way to add an cooldown on a Discord command. Im currently using c# for it.
I would save something like this in a database with the UUID and the timestamp when the last request was processed successfully by this User.
On the next request just check if the User is in the database and the last request is older than 5mins.
You will need a way of storing the GuildId and UserId of the user who called the command as well as the discord bot server time that the method was called. Then whenever that function is called, you check with the data and if the user data matches then see how much time has passed since last time.

Skype API call always cancelled

I have small application which calls phone numbers in Skype and allows to record conversations.
But it doesn't work with Skype versions after 7.5. I tried both Skype4COM and direct API:
For Skype4COM call always gets status clsCancelled, FailureReason is cfrMiscError. Below example code:
Skype skype = new SKYPE4COMLib.Skype();
if (!skype.Client.IsRunning)
{
skype.Client.Start(true, true);
}
skype.Attach(skype.Protocol, true);
Call call = skype.PlaceCall("+17606604690");
For direct API call status is MISSED. I'm using following command to start a call CALL +17606604690. It is possible to start call with somebody from your contact list by starting IM with him and bringing Skype client in focus, but this approach doesn't work for mobile numbers.
I guess Skype API changed after version 7.5, because I see that other applications still able to place calls. I'm also aware about Skype URLs, but they have big delays and won't let you know if call fails.
There is some discussion of this problem here, with a work‐around:
I made a shortcut to only call the skypecall part and surprisingly, if i spam it, it starts in. A triple try-catch cycle does the trick, but to make sure, i just applied force retry until its status becomes "ringing"

Lync SDK Start Audio Video Call with Send only UI Suppression mode

I am trying to build application for conferencing using Lync SDK in UI Suppression mode, the application is close to the Meet Now feature in lync so that one user will send his Video/Audio to all other users in conversation, my code is:
// Add conversation using
_LyncClient.ConversationManager.AddConversation();
// When Conversation added add participants
// User 1 will broadcast video/audio
_Conversation.AddParticipant(_LyncClient.ContactManager.GetContactByUri(user1));
// User 2 and User 3 will only recieve audio video
_Conversation.AddParticipant(_LyncClient.ContactManager.GetContactByUri(user2));
_Conversation.AddParticipant(_LyncClient.ContactManager.GetContactByUri(user3));
// Start the audio call from user1 machine
avModality.BeginConnect(AVCallback);
// When recieve the call in user2, user 3 stop mic using mute
_Conversation.SelfParticipant.BeginSetMute(true, (ar) =>
{
_Conversation.SelfParticipant.EndSetMute(ar);
}, _Conversation.SelfParticipant);
// and same technique for video
It works but i noticed that the performance of the call is affected each time a user enters the conversation and the conversation goes to Hold then Retrive states until user is added.
How Can I start a call in one way only send (not send recive), i tried the following:
avModality.BeginConnect(AVCallback, ChannelState.Send);
but it didn't work, also i have a look on the Conversation Properties, Moadilty Properties
but nothing looks helpful.
the only thing i found related is avModality.AudioChannel.State but i can't find a way to set this property?
Can anyone help?
I managed to create a one way video call by starting an audio call from the user who is sending the video and then in ModalityStateChanged calling avModality.VideoChannel.BeginStart once the call was connected.
Hope this helps.

Categories