Help - Search - Members - Calendar
Full Version: How to make a call in c#
Skype Community > English > Development, Betas and Skype Garage > Skype Public API
Gnorro
Hi
I have some problem understanding skype api
I would like to do a C# application that calls different telephone numbers and when a user answers, I want my application to play a registered message.

I don't know if this is possible using skype api and how to do it.

I use Interop.SKYPE4COMLib.dll to get skype functions. I can instantiate Skype object and I also tried succesfully to send a chat message to another user. But I don't know how to make calls.

I user this code:
public void Skype_CallStatus(Call call, TCallStatus status)
{
// Write Call Status to Window
if ((status > TCallStatus.clsUnplaced) && (status < TCallStatus.clsOnHold) && (status != TCallStatus.clsFailed))
{
Command cmd = new CommandClass();
cmd.Command = "ALTER CALL " + call.Id + " SET_INPUT FILE=\"C:\\skype\\TestSkype\\msg.wav\"";
skype.SendCommand(cmd);
}
else
{
// Could Stop or Resume something when a call stops here
}
}



thanks for your help

bye
Gnorro
I know I can use the command ALTER CALL, passing the call Id and the filename to play.

But if I execute this code:
Call call = new Call();
call.set_InputDevice(TCallIoDeviceType.callIoDeviceTypeFile, "msg.wav");

I get this error:
Errore HRESULT E_FAIL restituito da una chiamata a un componente COM.

and the I don't know how to use the call object to make a call

can you help me please?
TheUberOverlord
QUOTE(Gnorro @ Sun Mar 11 2007, 09:28) [snapback]370683[/snapback]

I know I can use the command ALTER CALL, passing the call Id and the filename to play.

But if I execute this code:
Call call = new Call();
call.set_InputDevice(TCallIoDeviceType.callIoDeviceTypeFile, "msg.wav");

I get this error:
Errore HRESULT E_FAIL restituito da una chiamata a un componente COM.

and the I don't know how to use the call object to make a call

can you help me please?


3 Things.

1. The Wav file must be 16khz 16 bit sample PCM format
2. Check your path to make sure "msg.wav" is really in the default path
3. You can't change input device file info unless the call is in progress.
Gnorro
there is something wrong

this is my code:

SKYPE4COMLib.Skype skype = new SKYPE4COMLib.SkypeClass();
// Connect to API
skype.Attach(6, true);

Command cmd = new CommandClass();
cmd.Blocking = true;

string strCmd = "CALL \"XXX\" INPUT SOUNDCARD=\"default\", PORT=\"12345\", FILE=\"" + @"C:\skype\TestSkype\msg.wav" + "\"";
cmd.Command = strCmd;
skype.SendCommand(cmd);

When the user answers he doesn't hear anything.
The file is in the right path. Is there an example file in the right format that I can try? I'm not able to manager file audio formats.

If I have to use ALTER CALL command how can I get the call id?

thanks
Gnorro
QUOTE(TheUberOverlord @ Sun Mar 11 2007, 18:39) [snapback]370725[/snapback]

3 Things.

1. The Wav file must be 16khz 16 bit sample PCM format
2. Check your path to make sure "msg.wav" is really in the default path
3. You can't change input device file info unless the call is in progress.


ok, it works. this is my code:

SKYPE4COMLib.Skype skype = new SKYPE4COMLib.SkypeClass();
skype.Attach(6, true);

Command cmd = new CommandClass();
cmd.Blocking = true;

string strCmd = "CALL \"098765432\" INPUT SOUNDCARD=\"default\", PORT=\"666\", FILE=\"C:\\skype\\TestSkype\\msg.wav" + "\"";
cmd.Command = strCmd;
skype.SendCommand(cmd);

CallCollection callc = skype.ActiveCalls;
Call call = callc[1];

cmd.Command = "ALTER CALL " + call.Id + " SET_INPUT FILE=\"C:\\skype\\TestSkype\\msg.wav\"";

skype.SendCommand(cmd);


if I execute this code I have an error because the alter call should be done whe the call is already started.
But how can I get the "user answers" event?

thanks
TheUberOverlord
QUOTE(Gnorro @ Sun Mar 11 2007, 14:22) [snapback]370786[/snapback]

ok, it works. this is my code:

SKYPE4COMLib.Skype skype = new SKYPE4COMLib.SkypeClass();
skype.Attach(6, true);

Command cmd = new CommandClass();
cmd.Blocking = true;

string strCmd = "CALL \"098765432\" INPUT SOUNDCARD=\"default\", PORT=\"666\", FILE=\"C:\\skype\\TestSkype\\msg.wav" + "\"";
cmd.Command = strCmd;
skype.SendCommand(cmd);

CallCollection callc = skype.ActiveCalls;
Call call = callc[1];

cmd.Command = "ALTER CALL " + call.Id + " SET_INPUT FILE=\"C:\\skype\\TestSkype\\msg.wav\"";

skype.SendCommand(cmd);
if I execute this code I have an error because the alter call should be done whe the call is already started.
But how can I get the "user answers" event?

thanks


Not sure why you are using the API interface if you want to use Skype4COM? Look at my Call transfer example, why not simply use the Skype4COM interface, here is the example:

http://share.skype.com/sites/devzone/2007/...nsfer.html#more

Once you get a call status returned of inprogress you can do the alter call via Skype4COM lib. As you can see you qualified the path in this case vs just pasing the filename, so before, you may not have been passing the right file path.

To get the path that your C# program is using simply do:
CODE

string path;
path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);


Or pass a hard coded path, but not simply the file name, because the path may not be pointing to the folder you think it is.
Gnorro
QUOTE(TheUberOverlord @ Sun Mar 11 2007, 20:35) [snapback]370796[/snapback]

Not sure why you are using the API interface if you want to use Skype4COM? Look at my Call transfer example, why not simply use the Skype4COM interface, here is the example:

http://share.skype.com/sites/devzone/2007/...nsfer.html#more

Once you get a call status returned of inprogress you can do the alter call via Skype4COM lib. As you can see you qualified the path in this case vs just pasing the filename, so before, you may not have been passing the right file path.

To get the path that your C# program is using simply do:
CODE

string path;
path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);


Or pass a hard coded path, but not simply the file name, because the path may not be pointing to the folder you think it is.


sorry but I didn't understand your last post.
Was my code correct? I think yes because it works. I tryed to download and open your example but it asks me a password that I don't know. I opened it with visual studio 2005 pro.
I noticed that if I call a skype user the audio file start when the user answers. But when I call a mobile phone the audio file starts when the call was done by the application, not when the user answer, and so the users hears only a part of the message. And I have to do that

any ideas?
TheUberOverlord
QUOTE(Gnorro @ Sun Mar 11 2007, 15:07) [snapback]370812[/snapback]

sorry but I didn't understand your last post.
Was my code correct? I think yes because it works. I tryed to download and open your example but it asks me a password that I don't know. I opened it with visual studio 2005 pro.
I noticed that if I call a skype user the audio file start when the user answers. But when I call a mobile phone the audio file starts when the call was done by the application, not when the user answer, and so the users hears only a part of the message. And I have to do that

any ideas?


You should still be able to read the source code in the example. All I am saying is, that there is no need to use the command API interface from the Skype4COM lib, all of this can be done using the Skype4COM lib, without using commands to the API. Your initial failure was most likely becuase your .wav file was not found, because the path to the file was wrong.

There should be no difference to when the .wav file plays based on if a call is a mobile or landline call, one should not start playing later than the other.

You need to learn how to use the "Call Status" events so that you can sense when a outbound call has been answered. By using the Command API interface, I think you are over-complicating the code.
Gnorro
QUOTE(TheUberOverlord @ Sun Mar 11 2007, 21:49) [snapback]370829[/snapback]

You should still be able to read the source code in the example. All I am saying is, that there is no need to use the command API interface from the Skype4COM lib, all of this can be done using the Skype4COM lib, without using commands to the API. Your initial failure was most likely becuase your .wav file was not found, because the path to the file was wrong.

There should be no difference to when the .wav file plays based on if a call is a mobile or landline call, one should not start playing later than the other.

You need to learn how to use the "Call Status" events so that you can sense when a outbound call has been answered. By using the Command API interface, I think you are over-complicating the code.


You mean that i didn't need to use command like CALL and ALTER?
Yes you're rigth, but in that moment that was the only solution in my head

however...thi is my final code:

private void button2_Click(object sender, EventArgs e)
{
skype.Attach(6, true);
Call cl = skype.PlaceCall("user", null, null, null);
}

public void Skype_CallStatus(Call call, TCallStatus status)
{

if (status == TCallStatus.clsInProgress)
{
call.set_InputDevice(TCallIoDeviceType.callIoDeviceTypeFile, @"C:\skype\TestSkype\msg.wav");
}
}

very simple

thank you very much
TheUberOverlord
QUOTE(Gnorro @ Sun Mar 11 2007, 16:36) [snapback]370838[/snapback]

You mean that i didn't need to use command like CALL and ALTER?
Yes you're rigth, but in that moment that was the only solution in my head

however...thi is my final code:

private void button2_Click(object sender, EventArgs e)
{
skype.Attach(6, true);
Call cl = skype.PlaceCall("user", null, null, null);
}

public void Skype_CallStatus(Call call, TCallStatus status)
{

if (status == TCallStatus.clsInProgress)
{
call.set_InputDevice(TCallIoDeviceType.callIoDeviceTypeFile, @"C:\skype\TestSkype\msg.wav");
}
}

very simple

thank you very much


Great :-)

Be careful however, you may wish to check if the call is an outbound call in your case, otherwise, you would start playing this message for inbound calls as well. So you may wish to check.

CODE

if ((call.Type == TCallType.cltOutgoingPSTN) && (status == TCallStatus.clsInProgress))
{
Your Code here
}

Tharivol
Hi,

i have to do the same thing as gnorro. i read the messages here and looked into uberoverlord's code but as i am very new to this Skype4COMLib i couldn't understand it fully. I added the library into references in visual studio 2005. Can u help me from the beginning about what i should do please? sadsmile.png
Tharivol
Hi all,

I managed to call someone by placeCall but i can't listen the event of clsInProgress. How can i use the event handler of skype4comlib with the method of gnorro?
public void Skype_CallStatus(Call cl, TCallStatus status)
{
if (status == TCallStatus.clsInProgress)
{
cl.set_InputDevice(TCallIoDeviceType.callIoDeviceTypeFile, @"C:\Skype\TestSkype\aherohasfallen.wav");
}
}

i tried Call cl.Status = new SKYPE4COMLib._ISkypeEvents_CallStatusEventHandler(tSkype_CallStatus);

But that doesnt work.

Thanks for your time.
Tharivol
Also can you help me how to call a mobile phone by using c# guys?

I tried the following code but that doesn't work,

Call cl = new Call();
Skype skype = new Skype();
string phoneNumber = "...";


skype.Attach(6, true);

skype.ActiveCalls.Add(cl);

cl.Transfer(phoneNumber);

In the last row it gives an hresult e_fail exception sadsmile.png

Thanks
TheUberOverlord
QUOTE (Tharivol @ Fri Mar 21 2008, 14:40)
Go to the original post
Also can you help me how to call a mobile phone by using c# guys?

I tried the following code but that doesn't work,

Call cl = new Call();
Skype skype = new Skype();
string phoneNumber = "...";


skype.Attach(6, true);

skype.ActiveCalls.Add(cl);

cl.Transfer(phoneNumber);

In the last row it gives an hresult e_fail exception sadsmile.png

Thanks


You should use PlaceCall NOT call transfer.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.