So I know this API is quite old and very undocumented, exactly the reason that I'm making a SO question, so I wanted to know how I can select a chat in Skype using the C# Skype Desktop API, I've done some looking around but most people seem to be using WinForms to make their app, mine's just a simple console application, code:
Skype Skype = new Skype();
Skype.Attach(5, true);
Skype.Chat.SendMessage("Hello ??");
Parser.Pause();
On runtime, I of course get an exception telling me I need to select a chat, but I'm not sure as to how I can do that, I've looked here but that didn't help me much.
Is there a way to reference a chat easily using a specific code? etc... Thanks!
I have constructed this snippet which should help you...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Channels;
using System.Text;
using System.Threading.Tasks;
using SKYPE4COMLib;
namespace skypeExperiment
{
class Program
{
static void Main(string[] args)
{
Skype s = new Skype();
s.Attach();
if (!s.Client.IsRunning)
{
// start minimized with no splash screen
s.Client.Start(true, true);
}
// wait for the client to be connected and ready
//you have to click in skype on the "Allow application" button which has popped up there
//to allow this application to communicate with skype
s.Attach(6, true);
//this will print out all the chat names to the console
//it will enumerate all the chats you've been in
foreach (Chat ch in s.Chats)
{
Console.WriteLine(ch.Name);
}
//pick one chat name of the enumerated ones and get the chat object
string chatName = "#someskypeuser/someskypeuser;9693a13447736b9";
Chat chat = GetChatByName(s, chatName);
//send a message to the selected chat
if (chat != null)
{
chat.SendMessage("test");
}
else
{
Console.WriteLine("Chat with that name was not found.");
}
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
}
private static Chat GetChatByName(Skype client, string chatName)
{
foreach (Chat chat in client.Chats)
{
if (chat.Name == chatName) return chat;
}
return null;
}
}
}
Instead of using an existing chat object, you can create new chat object with method
Chat chat = s.CreateChatWith("name of the user to chat with");
chat.SendMessage("test");
You can create a group chat with:
Group mygroup = s.CreateGroup("mygroup");
mygroup.AddUser("user1");
mygroup.AddUser("user2");
Chat myGroupChat = s.CreateChatMultiple(mygroup.Users);
myGroupChat.SendMessage("test");
or create method to retrieve group by display name
private static Group GetGroupByDisplayName(Skype client, string groupDisplayName)
{
foreach (Group g in client.Groups)
{
if (g.DisplayName == groupDisplayName)
{
return g;
}
}
return null;
}
and use it then like:
Group majesticSubwayGroup = GetGroupByDisplayName("majesticsubway");
Chat majesticSubwayGroupChat = s.CreateChatMultiple(majesticSubwayGroup.Users);
majesticSubwayGroupChat.SendMessage("test");
Related
I want to get a list of installed MIDI Devices in Windows 10, using the Windows 10 UWP MIDI API.
This article shows example code to get a list of MIDI devices and their IDs, using C#:
using Windows.Devices.Midi;
using Windows.Devices.Enumeration;
...
private async void ListMidiDevices()
{
// Enumerate Input devices
var deviceList = DeviceInformation.FindAllAsync(
MidiInPort.GetDeviceSelector());
foreach (var deviceInfo in deviceList)
{
Console.WriteLine(deviceInfo.Id);
Console.WriteLine(deviceInfo.Name);
Console.WriteLine("----------");
}
// Output devices are enumerated the same way, but
// using MidiOutPort.GetDeviceSelector()
}
I tried inserting the code for ListMidiDevices in the Visual Studio Community 2015 "Hello World" example program. I put the code block in place of Console.WriteLine("Hello World!");
in the "hello world" console example. I added the "using" statements above in the proper place.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Devices.Midi;
using Windows.Devices.Enumeration;
namespace ConsoleApplicationHelloWorld
{
class Program
{
static void Main(string[] args)
{
// Enumerate Input devices
var deviceList = await DeviceInformation.FindAllAsync(
MidiInPort.GetDeviceSelector());
foreach (var deviceInfo in deviceList)
{
System.Diagnostics.Debug.WriteLine(deviceInfo.Id);
System.Diagnostics.Debug.WriteLine(deviceInfo.Name);
System.Diagnostics.Debug.WriteLine("----------");
}
// Output devices are enumerated the same way, but
// using MidiOutPort.GetDeviceSelector() }
}
}
Edit - VS wasn't building the UWP type. I upgraded to VS Community 2019, and installed ConsoleAppUniversal.vsix. Then I could create a new project - Console App C# Universal:
using System;
using Windows.Devices.Midi;
using Windows.Devices.Enumeration;
// This example code shows how you could implement the required main function for a
// Console UWP Application. You can replace all the code inside Main with your own custom code.
// You should also change the Alias value in the AppExecutionAlias Extension in the
// Package.appxmanifest to a value that you define. To edit this file manually, right-click
// it in Solution Explorer and select View Code, or open it with the XML Editor.
namespace ConsoleAppCsharpUniversal
{
class Program
{
static void Main(string[] args)
{
if (args.Length == 0)
{
Console.WriteLine("starting - no args");
// Enumerate Input devices
var deviceList = DeviceInformation.FindAllAsync(
MidiInPort.GetDeviceSelector());
foreach (var deviceInfo in deviceList)
{
Console.WriteLine(deviceInfo.Id);
Console.WriteLine(deviceInfo.Name);
Console.WriteLine("----------");
}
Console.WriteLine("finish - no args");
}
else
{
for (int i = 0; i < args.Length; i++)
{
Console.WriteLine($"arg[{i}] = {args[i]}");
}
}
Console.WriteLine("Press a key to continue: ");
Console.ReadLine();
}
}
}
Now the only remaining error is "foreach statement cannot operate on variables of type IAsyncOperation<DeviceInformationCollection> because IAsyncOperation<DeviceInformationCollection> does not contain a public instance definition for GetEnumerator"
Is there another way to access the device information without using an async method?
You have to make sure your project is targeting at least C# 7.1 (I think the template does have this out-of-the-box in VS 2019) and use the async Main method feature:
Your method signature will change to:
public static async Task Main(string[] args)
{
...
}
And then you need to await the FindAllAsync method:
var deviceList = await DeviceInformation.FindAllAsync(
MidiInPort.GetDeviceSelector());
Note: You can change the C# version by opening the csproj file in a text editor and adding the following into a <PropertyGroup>:
<LangVersion>7.1</LangVersion>
or even (if you want the latest features):
<LangVersion>latest</LangVersion>
I am new in c#
I am trying to send command to USB port(usbport=========fx3(Cypress chip), to light on LED than with in the custom board))
I tried to scanport but it was failed because my computer(win10) recognized the usb as camera(fx3 is chip that image processing)
so i found this code in sysnet.pe.kr
using System;
using System.Threading.Tasks;
using Windows.Devices.Enumeration;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
ListDevices().GetAwaiter().GetResult();
}
private static async Task ListDevices()
{
var devices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
foreach (var item in devices)
{
Console.WriteLine($"{item.Id}: {item.Name}");
devices.
}
}
}
}
it works!!! so I found port
but i don't have idea how to send command to the port!!!
please help me ㅠㅠ
First you must read your camera documentation (from producer website or .. , it may have programing sdk)
Otherwise you can use LibUsbDotNet
Ok, firstly, I'm not very advanced at this, xD
In public override void OnMessage (string message, EChatEntryType type) I want to execute a series of tests to figure out which response to send.
The first test is to see if the message starts with a command. I'm an admin for a CSGO server group called "Warmup Servers" and this will be a string of parts which will generate and feed back information into a separate log file.
So I'm working on a custom UserHandler.cs for my steambot. I plan on writing a simple script, so that I can do exec [botname] TGTOnline & exec [botname] TGTOffline to tell the bot if using its account. (Like playing games or something on that account).
To test if the message starts with any of the predefined responses. (More to be added later)
To test if the bot has sent a message before. I don't want someone to start a conversation with me and the bot to be sending its default response every time it recieves a message, it would be annoying for both parties.
So before the default message is called, I need to have a function which checks to see if the bot account (Both bot response or human response) has sent a message to the user recently (Last 5 Minutes) and if it has, tell the bot to do nothing...
However I have no clue on where to start with this script and would love some advice!
Here is my TGTUserHandler.cs section which relates:
using System;
using SteamKit2;
using System.Threading.Tasks;
using System.Collections.Generic;
using SteamTrade;
using SteamTrade.TradeOffer;
using SteamTrade.TradeWebAPI;
namespace SteamBot
{
public class TGTUserHandler : UserHandler
{
private bool TGTOnline = false;
private TaskCompletionSource<string> _UserReport;
public TGTUserHandler(Bot bot, SteamID sid) : base(bot, sid) { }
private bool HandleUserReport(string message)
{
if (_UserReport == null)
return false;
//to be scripted in the morning
_UserReport = null;
return true;
}
public override void OnMessage(string message, EChatEntryType type)
{
if (message.StartsWith("!"))
{
if (message.StartsWith("!help"))
{
SendChatMessage("Welcome to the TGTGaming Automated Bots, We have very limited commands and currently do not do any type of automated trade. Here is the list of current commands you can use:");
SendChatMessage("!WarmupServers [help | Report | Issue] | This command is used for all issues related to the WarmupServer's. Do `!Warmupservers help` for more information");
SendChatMessage("!getadmin | This command is used to contact a TGTGaming administrator. Please do `!getadmin help` for more information");
}
if (message.StartsWith("!WarmupServers"))
{
if (message.StartsWith("!WarmupServers help"))
{
SendChatMessage("Warmup Servers Automated Support by TGTGamer");
SendChatMessage("Commands:");
SendChatMessage("!WarmupServers Report | Used to report a user for specific reasons. This is step by step process");
SendChatMessage("!WarmupServers issue | Used to report a issue with the servers. This is a step by step process");
}
if (message.StartsWith("!WarmupServers Report"))
{
GetUserResponse("You have started the user reporting process, please confirm this is what you wanted to do. [y/n]");
if (message.StartsWith("y"))
{
SendChatMessage("A few quick questions first, please respond yes or no");
GetUserResponse("Are you still in the server?");
if (message.StartsWith("y"))
{
GetUserResponse("Is the User you wish to report still in your server?");
if (message.StartsWith("y"))
{
GetUserResponse("Is there a VIP in the server?");
if (message.StartsWith("y"))
{
SendChatMessage("Please ask the VIP to do a !startvote on this user with your reason.");
}
else
{
_UserReport = new TaskCompletionSource<string>();
return _UserReport.Task;
}
}
else
{
_UserReport = new TaskCompletionSource<string>();
return _UserReport.Task;
}
}
else
{
_UserReport = new TaskCompletionSource<string>();
return _UserReport.Task;
}
}
else
{
SendChatMessage("You have cancelled this action");
}
}
}
}
else
{
if (TGTOnline)
{
//general Responses
if (message.StartsWith("Hello"))
{
SendChatMessage("What's up?");
}
if (message.StartsWith("Heya"))
{
SendChatMessage("Hello");
}
if (message.StartsWith("Hi"))
{
SendChatMessage("Heya");
}
else
{
//defualt response
SendChatMessage(Bot.ChatResponse);
}
}
else
{
//defualt response
SendChatMessage(Bot.ChatResponse);
}
}
}
}
}
All and any help will be appreciated.
Kind regards.
TGT
External Links you may find useful:
Bot Github: https://github.com/Jessecar96/SteamBot/
UserHandler.cs: https://github.com/Jessecar96/SteamBot/blob/master/SteamBot/UserHandler.cs
Footnotes:
Steam Subscriber Agreement:
The steam Subscriber Agreement States the following:
You may not use Cheats, automation software (bots), mods, hacks, or
any other unauthorized third-party software, to modify or automate any
Subscription Marketplace process.
As I am using this bot to automate 3rd party server actions (Rcon Kick's, Server restarts & such) it is within the steam subscriber agreement acceptance for bots. If I then started to sell or buy automatically with this bot, it would breach the subscriber agreement.
I have a notification system for my Asp.net application that uses sql-server. Currently, when there is an update on certain tables email alert sent. I am wondering, if there is a way to use Lync instead of email so that when tables updated, users will get Lync messages?
You can use Lync client for .Net. Here is the link- https://code.msdn.microsoft.com/lync/Lync-2013-Use-the-Lync-47ded7b4
Below is a sample code.
using Microsoft.Lync.Model;
using Microsoft.Lync.Model.Conversation;
private static void SendMessage()
{
try
{
string[] arrRecepients = { "sip:receiver1#domain.com", "sip:receiver2#domain.com" }; //add your recepients here
LyncClient lyncClient = LyncClient.GetClient();
Conversation conversation = lyncClient.ConversationManager.AddConversation();
foreach (string recepient in arrRecepients)
{
conversation.AddParticipant(lyncClient.ContactManager.GetContactByUri(recepient));
}
InstantMessageModality imModality = conversation.Modalities[ModalityTypes.InstantMessage] as InstantMessageModality;
string message = GetNotification(); //use your existing notification logic here
imModality.BeginSendMessage(message, null, null);
}
catch (Exception ex)
{
}
}
I was working on a security monitor application and the best approach i found was Skype.
when a possible intrusion occurs the application calls a specified Skype ID which is probably my android phone i am done with all the image processing stuff. But i am stuck with this Skype API i wrote this piece of code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SKYPE4COMLib;
namespace SkypeCall
{
class Program
{
static void Main(string[] args)
{
Skype skype;
skype = new Skype("Skype4COM.Skype", "Skype_");
Call call = skype.PlaceCall(SkypeID);
call.StartVideoSend();
}
}
}
This initiates a voice call but in the call.StartVideoSend(); shows an error
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in SkypeCall.exe
Additional information: CALL: Action failed
i even tried this but i guess that's old API and couldn't get anything out of it.
And not even by sending commands .
if somebody would help me out i'll be grateful.
I think you need to wait until the call is connected.
easiest way would be to test the call.Status
class Program
{
static void Main(string[] args)
{
Skype skype;
skype = new SKYPE4COMLib.Skype();
string SkypeID = args[1];
Call call = skype.PlaceCall(SkypeID);
do
{
System.Threading.Thread.Sleep(1);
} while (call.Status != TCallStatus.clsInProgress);
call.StartVideoSend();
}
}
You could also add an event, however I think this will fire on every call so unless you are only using it for this project it might be too much.
class Program
{
static string SkypeID = "";
static void Main(string[] args)
{
Skype skype;
skype = new SKYPE4COMLib.Skype();
skype.CallStatus += new _ISkypeEvents_CallStatusEventHandler(skype_CallStatus);
Call call = skype.PlaceCall(SkypeID);
Console.ReadKey();
}
static void skype_CallStatus(Call pCall, TCallStatus Status)
{
if (Status == TCallStatus.clsInProgress && pCall.PartnerHandle == SkypeID) { pCall.StartVideoSend(); }
}
}