Skype API in VB.net
Nere is a little code that looks for a command and reacts to it. It is written in VB.net 2010. To test it, you’ll need Skype on two computers connected on the interent. In my case, my desktop and Bender
Running VB from the robot (or remote computer) create a new VB project and cut and paste the code below into it’s main form
Don’t forget to reference the Skyp4Com object in 'add reference’
Run it
from your desktop, connect to the remote
In the chatbox type one of the commands (Hint: look through the code for the process command method) For example !who should give you my name, !help will say no help etc.
$xx are sequences intended to be sent to the robot
$f would cause an ‘f’ to be sent to Bender
VB expresess 2010 is a free download from Microsoft.
If you run this, you wil realize just how easy it is to integrate Skype control into your robot.
==============================================================
Public Class Form1
Public WithEvents oSkype As New SKYPE4COMLib.Skype
Private Const robotName = “Bender”
Private Const trigger = “!” ’ Say !help
Private Const robotTrigger = “$” ’ Say $f
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
oSkype.Attach(7, False)
End Sub
Private Sub skype_MessageStatus(ByVal msg As SKYPE4COMLib.ChatMessage,
ByVal status As SKYPE4COMLib.TChatMessageStatus) Handles oSkype.MessageStatus
Dim command As String
Dim robot As String
’ Proceed only if the incoming message is a trigger
If msg.Body.IndexOf(trigger) = 0 Then
’ Remove trigger string and make lower case
command = msg.Body.Remove(0, trigger.Length).ToLower()
’ Send processed message back to skype chat window
oSkype.SendMessage(msg.Sender.Handle, robotName + " Says: " + ProcessCommand(command))
End If
’ Proceed only if the incoming message is a command to the robot
If msg.Body.IndexOf(robotTrigger) = 0 Then
’ Remove trigger string and make lower case
robot = msg.Body.Remove(0, robotTrigger.Length).ToLower()
’ Send processed message back to skype chat window
oSkype.SendMessage(msg.Sender.Handle, robotName + " Responds to: " + ProcessCommandToRobot(robot))
End If
End Sub
Private Function ProcessCommandToRobot(ByVal str As String)
Dim result As String
Dim robotCommand As String
Select str
Case “f”
robotCommand = “f”
result = “Forward”
Case “b”
robotCommand = “b”
result = “Reverse”
Case “r”
robotCommand = “r”
result = “Right”
Case “l”
robotCommand = “l”
result = “Left”
Case “vr”
robotCommand = “vr”
result = “Veer Right”
Case “vl”
robotCommand = “vl”
result = “Veer Left”
Case “s”
robotCommand = " "
result = “Stop”
End Select
’SendCommandToRobot(robotCommand) ’ not written yet
Return result
End Function
Private Function ProcessCommand(ByVal str As String)
Dim result As String
Select Case str
Case “hello”
result = “Hello!”
Case Is = “help”
result = “Sorry no help available”
Case “date”
result = "Current Date is: " +
DateTime.Now.ToLongDateString()
Case “time”
result = "Current Time is: " + DateTime.Now.ToLongTimeString()
Case “who”
result = "It is David, aka dlevartt " +
“who wrote this program”
Case Else
result = “Sorry, I do not recognize your command”
End Select
Return result
End Function
End Class