Author Topic: Random Messages for Multiple People  (Read 4656 times)

0 Members and 1 Guest are viewing this topic.

rebelmaveric19

  • $upporter
  • Jr. Member
  • *****
  • Posts: 41
  • Karma: 2
    • View Profile
Random Messages for Multiple People
« on: May 11, 2014, 02:48:36 PM »
ALright I started a new thread to get my python script working because its not about integration now but.....python.
For two days I have read countless webpages on python and cant get this to work:
Code: [Select]
import urllib
import random

def randomMsg(tts):
    RogersS4APIKey= "(My APIKey)"
    HeathersAPIKey= "Enter your API KEY here in quotes (in quotes defines it as a string in Python)"
    ttsList=tts.split("|")
    myMsg=random.choice(ttsList)
    #vc.callAction("TTS.Speak",myMsg, None)
    vc.callAction("Map.Get","WhoisTalkingtoJarvis&&who is talking to me",None)
    myLastResult=vc.getObject("LastResult","")
    if myLastResult == "roger":
   urllib.urlopen("http://autoremotejoaomgcd.appspot.com/sendmessage?key="+RogersS4APIKey+"&message=jarvistalk=:="+myMsg)
    if myLastResult == "heather":
        urllib.urlopen("http://autoremotejoaomgcd.appspot.com/sendmessage?key="+HeathersAPIKey+"&message=jarvistalk=:="+myMsg)
    vc.callAction("OSD.ShowText",myMsg, None)
    #if you want to use VC, uncomment (remove #) the following line:
    #vc.callAction("Scrape","http://autoremotejoaomgcd.appspot.com/sendmessage?key="+RogersS4APIKey+"&message=jarvistalk=:="+myMsg,None)
I have read where not to use tab and only use 4 spaces and reworked my call.action and still gives my an error.......I am at the point of breaking my monitor, may I have a little guidance.
« Last Edit: May 11, 2014, 04:07:41 PM by rebelmaveric19 »

rebelmaveric19

  • $upporter
  • Jr. Member
  • *****
  • Posts: 41
  • Karma: 2
    • View Profile
Re: Random Messages for Multiple People
« Reply #1 on: May 11, 2014, 02:51:16 PM »
Nevermind there WAS a damn tab in there..........I am cutting my picky off :bonk............and when I try to initiate the string it gives me an error now.......really trying my patience

Atleast I posted my code in the python section and what this does is if you send an event everytime tasker sends a phrase to set a map table key to who your computer is talking to.....you/your brother/ex wife......it will only send tts (i use autoremote) back to the phone that it originated from.....so if your dog sent the phrase it will not send tts back to your phone
« Last Edit: May 11, 2014, 03:07:55 PM by rebelmaveric19 »

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Random Messages for Multiple People
« Reply #2 on: May 11, 2014, 03:13:37 PM »
The tab/space thing is definitely a headache.

Are you saying the above python code is now working successfully for you now that you've fixed your tabs?

From here, it looks as though you need to fix the syntax of the line:
Code: [Select]
vc.callAction("Map.Get","WhoisTalkingtoJarvis","who is talking to me")
I'm assuming "who is talking to me" is a key in your map table? (i.e., a parameter, not a payload?)

That is, the Map.Get action takes 2 parameters: http://voxcommando.com/mediawiki/index.php?title=Actions#Get

Per the Python documentation:
Code: [Select]
void callAction(string strActionType, string strParams, List<string> payloads)
The documentation also provides a callAction example that has multiple parameters (http://voxcommando.com/mediawiki/index.php?title=Python#Actions):
Code: [Select]
vc.callAction("OSD.ShowText","Display me for 5 seconds at the top&&5000&&-10", None)
« Last Edit: May 11, 2014, 06:05:11 PM by nime5ter »
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Random Messages for Multiple People
« Reply #3 on: May 11, 2014, 03:18:41 PM »
... I'm seeing some other issues and will get back to you on those. (multitasking)

OK, I'm back ...

your map values "roger" and "heather" are strings, but in your code, you're not defining them that way, so Python will think you're referring to variables (or basically, won't know what those terms are).

Those lines should instead be:
Code: [Select]
if myLastResult=="roger":
And
Code: [Select]
if myLastResult=="heather":
« Last Edit: May 11, 2014, 03:25:16 PM by nime5ter »
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Random Messages for Multiple People
« Reply #4 on: May 11, 2014, 03:29:44 PM »
It is also generally good form to make sure you've got some means of catching "exceptions".

Right now, you've got two conditions (a map value of "roger" or a map value of "heather"), but it's conceivable that those won't always be met.

TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

rebelmaveric19

  • $upporter
  • Jr. Member
  • *****
  • Posts: 41
  • Karma: 2
    • View Profile
Re: Random Messages for Multiple People
« Reply #5 on: May 11, 2014, 03:36:03 PM »
so should it be like this
Code: [Select]
vc.callAction("Map.Get","WhoisTalkingtoJarvis","who is talking to me&&roger&&heather",)or use Map.Getkey?
I'm confused

This is only my second or third time messing with python so sorry if I am being stupid
« Last Edit: May 11, 2014, 03:41:08 PM by rebelmaveric19 »

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Random Messages for Multiple People
« Reply #6 on: May 11, 2014, 03:54:59 PM »
I have been assuming that you have a map table called "WhoisTalkingtoJarvis", and that you have a key "who is talking to me" that you are changing the value for via some other command: so that that value is either Roger or Heather.

Is that correct, or not?

(I think James suggested a different solution, but it's not important for now.)

The action Map.Get takes 2 parameters: the map table name, and the key for which you want to get the associated value.

You are not trying to pass it any payloads here, if I'm understanding your efforts correctly (and maybe I'm not). You are trying to *return* a value of either "roger" or "heather" as your LastResult.

Code: [Select]
vc.callAction("Map.Get","WhoisTalkingtoJarvis&&who is talking to me",None)
... You can test this directly in VC, right?
Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 1.9.3.3-->
<command id="925" name="Who is talking to Jarvis?" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>Map.Get</cmdType>
    <params>
      <param>WhoisTalkingtoJarvis</param>
      <param>who is talking to me</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>OSD.ShowText</cmdType>
    <params>
      <param>{LastResult}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <phrase>Who is talking to Jarvis?</phrase>
</command>


Or you can just look at your map table to see which is the value and which is the key. (If it's the other way around for whatever innovative reason, then you'd need to use Map.GetKey.)
« Last Edit: May 11, 2014, 03:58:39 PM by nime5ter »
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

rebelmaveric19

  • $upporter
  • Jr. Member
  • *****
  • Posts: 41
  • Karma: 2
    • View Profile
Re: Random Messages for Multiple People
« Reply #7 on: May 11, 2014, 04:04:21 PM »
yes sorry I didnt make that clear
"WhoisTalkingtoJarvis" is the Map Table
"who is talking to me" is the Map Key

and yes I am just trying to get the Value from that and pass it on to python

and yes the map Value is "roger" right now..........and it worked with
Code: [Select]
vc.callAction("Map.Get","WhoisTalkingtoJarvis&&who is talking to me",None)
BTW James did mention another way but I really am not good enough with python to "really" understand what he means but do have an idea about what he mention
is this way not "good" and maybe need to do it another way?

PS. Updated the original post with fixes
« Last Edit: May 11, 2014, 04:08:13 PM by rebelmaveric19 »

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Random Messages for Multiple People
« Reply #8 on: May 11, 2014, 04:15:56 PM »
Great, well, let us know if/when you get your code working.

Don't worry about the Sophisticated version. Go with what works for you, and hopefully you'll have fun learning a few things that will be helpful in the future (and can see how time intensive/nitpicky programming is, so you can better appreciate when coders get grumpy on occasion ;)).

When James has some time, I imagine he'll pipe up to explain about efficiency issues etc., but that's about "elegantly efficient" solutions versus "duct-tape functional" solutions. Most of us are bodgers -- content with the duct tape variety until such time as complications arise.

« Last Edit: May 11, 2014, 05:56:34 PM by nime5ter »
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

rebelmaveric19

  • $upporter
  • Jr. Member
  • *****
  • Posts: 41
  • Karma: 2
    • View Profile
Re: Random Messages for Multiple People
« Reply #9 on: May 11, 2014, 04:33:14 PM »
It is working now as we speak and thank you very much for helping me...as soon as you put your fix for vc.callaction up I was like.... :bonk.....I understood and promise it is stuck in my head now.

And yes I have a migraine (really) after trying to get this to work so I have a new found appreciation for coders (just wish I was good at it...limitless possibilities)

I tell people I am a technologically advanced "redneck"...I chew, spit, wear cowboy boots, drink beer and my "original" hobbies are drag racing and anything with a motor on it so.........I like duct tape

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Random Messages for Multiple People
« Reply #10 on: May 11, 2014, 09:47:31 PM »
BTW James did mention another way but I really am not good enough with python to "really" understand what he means but do have an idea about what he mention
is this way not "good" and maybe need to do it another way?

This method is fine.  I was just pointing out an alternative option that would probably be a bit more efficient.  Don't worry about it for now.  Once you are finished, maybe you can post your xml which you use to set the map tables based on the event from tasker, and when I have time (and left over brain power) I will put together an example of the other method.

rebelmaveric19

  • $upporter
  • Jr. Member
  • *****
  • Posts: 41
  • Karma: 2
    • View Profile
Re:
« Reply #11 on: May 15, 2014, 12:40:11 AM »
One thing I noticed after using this a couple of days is every command that I was using {LastResult} on....was messed up because every time randommsg.py runs it tests the last result to my name. I had to go in and set a variable before randommsg.py ran and then use that variable replacing my "{LastResult}". Just heads up foot anyone wanting to use this.....

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Random Messages for Multiple People
« Reply #12 on: May 15, 2014, 06:04:17 PM »
The VC-only way (sans Python) is probably also a reasonable solution. Along the lines of:

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 1.9.3.3-->
<commandGroup open="True" name="Send random TTS" enabled="True" prefix="" priority="0" requiredProcess="" description="">
  <command id="266" name="tts message" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="You'd use this action in any of your commands  instead of TTS.Speak (or instead of the Python call you're currently using).">
    <action>
      <cmdType>VC.TriggerEvent</cmdType>
      <params>
        <param>myTTS</param>
        <param>hello|greetings|hi there</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>tts message</phrase>
  </command>
  <command id="280" name="sendtoAutoRemote" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>Results.RegEx</cmdType>
      <params>
        <param>([^|]+)</param>
        <param>--</param>
        <param>{1}</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>Results.SetVar</cmdType>
      <params>
        <param>ttsRnd</param>
        <param>{Match.Rnd}</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <if ifBlockDisabled="False" ifNot="False">
      <ifType>(A)Contains(B)</ifType>
      <ifParams>{M:WhoisTalkingtoJarvis.who is talking to me}&amp;&amp;roger</ifParams>
      <then>
        <action>
          <cmdType>Scrape</cmdType>
          <params>
            <param>http://autoremotejoaomgcd.appspot.com/sendmessage?key={M:autoremoteAPI.roger}&amp;message=jarvistalk=:={var.ttsRnd}</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
      </then>
      <else>
        <action>
          <cmdType>Scrape</cmdType>
          <params>
            <param>http://autoremotejoaomgcd.appspot.com/sendmessage?key={M:autoremoteAPI.heather}&amp;message=jarvistalk=:={var.ttsRnd}</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
      </else>
    </if>
    <event>myTTS</event>
  </command>
</commandGroup>

The "sendtoAutoRemote" command references 2 different maps -- your "who's talking" map, and a map with your API keys.

The "send random TTS" command is just a proxy for the action you'd include in any of your commands where you're sending a TTS announcement to your mobiles via autoremote.
« Last Edit: May 15, 2014, 09:39:25 PM by nime5ter »
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Random Messages for Multiple People
« Reply #13 on: May 15, 2014, 10:58:51 PM »
So here's my python solution.  I think it is really the simplest and most efficient, if you don't mind using python.

Here is the python code:
Code: [Select]
import urllib
import random

def randomMsg(tts):
    ttsList=tts.split("|")
    myMsg=random.choice(ttsList)
    #vc.callAction("TTS.Speak",myMsg, None)
    vc.callAction("OSD.ShowText",myMsg, None)
    urllib.urlopen("http://autoremotejoaomgcd.appspot.com/sendmessage?key="+myApiKey+"&message=jarvistalk=:="+myMsg)
    print "http://autoremotejoaomgcd.appspot.com/sendmessage?key="+myApiKey+"&message=jarvistalk=:="+myMsg


def setApiKey(who):
    global myApiKey
    myApiKey = "??"
    if who == "roger":
        myApiKey = "123rogersapikeygoeshere"
    elif who == "heather":
        myApiKey = "123heathersapikeygoeshere"

Obviously you need to replace the two strings near the end with your actual api keys.

Here is the sample xml for the VC group.
Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 1.9.4.1-->
<commandGroup open="True" name="Send random TTS" enabled="True" prefix="" priority="0" requiredProcess="" description="">
  <command id="199" name="on launch run script" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>PY.ExecFile</cmdType>
      <params>
        <param>py\randomMsg.py</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <event>VC.Loaded</event>
  </command>
  <command id="215" name="set who roger" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>PY.ExecString</cmdType>
      <params>
        <param>setApiKey("roger")</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
  </command>
  <command id="224" name="set who heather" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>PY.ExecString</cmdType>
      <params>
        <param>setApiKey("heather")</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
  </command>
  <command id="234" name="test speak" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>PY.ExecString</cmdType>
      <params>
        <param>randomMsg("hello|hi there|what's up")</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
  </command>
</commandGroup>

The two commands
- set who roger
- set who heather

Are for testing only and would be replaced with the command triggered by your event, which is generated by your phone, and which contains the name of the user as a payload.  To use that payload you could change the way you call the python so that it looks like this:
Code: [Select]
setApiKey("{1}")

rebelmaveric19

  • $upporter
  • Jr. Member
  • *****
  • Posts: 41
  • Karma: 2
    • View Profile
Re: Random Messages for Multiple People
« Reply #14 on: May 16, 2014, 10:19:34 PM »
Thank you both for the two examples. I will test both methods over the next couple of days and see which one works better for me. I am in class all next week so I will not be able to "play" with it as much. Right now I am trying to explore more possibilities with using autoremote with VC. I made a pretty cool command to send a text file of running processes to my phone from any one of computers. I just say "jarvis send me running processes on the server/office/living room" and it sends the file to my phone. Thought that was pretty cool. I have been making enough success with VC that I went ahead and bought a Gigabyte Brix GB-BXi5-4200 mini computer that will run VC and some other stuff as a "control center" for all my computers around the house. Bit overkill but I found it at a good price ($250USD on ebay brand new) and will add 8gb of ram and 120 msata harddrive. The virtual computer I am running VC on right now is hogging up my ram on my server.