livebox:twitter

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revisionBoth sides next revision
livebox:twitter [2012/03/17 17:03] – [xAP Twitter] Diagram showing processing of Twitter command. karllivebox:twitter [2012/05/29 10:55] – [alias interpreter] brett
Line 32: Line 32:
 </code> </code>
  
-The commands you enter resolve the same way as the Google Calendar component (//See [[hah#calendar_aliases]]//) and require an [[hah_plugboard#alias_interpreter]] to resolve these into appropriate actions.  The diagram below shows the entire process.+The commands you enter resolve the same way as the Google Calendar component (//See [[google_calendar#calendar_aliases]]//) and require an [[#alias_interpreter]] to resolve these into appropriate actions.  The diagram below shows the entire process.
  
 {{:livebox:twitter_xap_process_v3.png|}} {{:livebox:twitter_xap_process_v3.png|}}
Line 63: Line 63:
 text=Hello World text=Hello World
 } }
 +</code>
 +
 +===== alias interpreter =====
 +
 +An alias engine is supplied on the HAH as a sample to install this
 +<code>
 +# cp /etc_ro_fs/plugboard/samples/aliasApplet.lua /etc/plugboard
 +</code>
 +
 +This is how the default alias engine looks - You'll want to edit this as you add twitter and google calender command shortcuts.
 +<code lua>
 +--[[ 
 +Alias interpreter
 +
 +Use to perform actions based on xAP alias class messages emitted by
 +both xap-twitter and xap-googlecal
 +--]]
 +
 +module(...,package.seeall)
 +
 +require("xap")
 +require("xap.bsc")
 +require("string")
 +rex = require("rex_posix")
 +
 +info={
 +   version="1.1", description="Alias Interpreter"
 +}
 +
 +pat={
 +    [rex.new("(relay) ([1-4]) (on|off)")]=function(m) rfRelayCmd(m) end,
 +    [rex.new("(rf) ([0-9]+) (on|off)")]=function(m) rfRelayCmd(m) end,
 +    [rex.new("tweet (.*)")]=function(m) tweet(m) end,
 +    "reboot" = function() os.execute("reboot") end
 +}
 +
 +function tweet(m)
 +  local msg = unpack(m)
 +  bsc.sendText("dbzoo.livebox.Twitter",msg)
 +end
 +
 +function rfRelayCmd(t)
 +  local addr1,addr2,state = unpack(t)
 +  bsc.sendState(string.format("dbzoo.livebox.Controller:%s.%s",addr1,addr2),state)
 +end
 +
 +function aliasEngine(frame)
 +  local alias = frame:getValue("command","text")
 +  for r,f in pairs(pat) do
 +      if type(r) == "string" then
 +         if r == alias then
 +            f()
 +         end
 +      else
 +        p={r:match(alias)}
 +        if #p > 0 then
 +            f(p)
 +        end
 +      end
 +  end
 +end
 +
 +function init()
 +  local f = xap.Filter()
 +  f:add("xap-header","class","alias")
 +  f:add("command","text",xap.FILTER_ANY)
 +  f:callback(aliasEngine)
 +end
 </code> </code>
  
  • livebox/twitter.txt
  • Last modified: 2012/05/29 10:59
  • by brett