Skip to content

Instantly share code, notes, and snippets.

@dungletri
Forked from TelegramSam/NeoSale
Created March 22, 2016 04:24
Show Gist options
  • Select an option

  • Save dungletri/e57c7ecf80a02114c0b6 to your computer and use it in GitHub Desktop.

Select an option

Save dungletri/e57c7ecf80a02114c0b6 to your computer and use it in GitHub Desktop.

Revisions

  1. @TelegramSam TelegramSam revised this gist Oct 11, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion NeoSale
    Original file line number Diff line number Diff line change
    @@ -21,7 +21,7 @@ ruleset a8x72 {
        dataset winner <- "https://spreadsheets.google.com/pub?key=<redacted>&single=true&gid=1&range=B2&output=txt" cachable for 1 second;
      }

      rule first_rule is active {
      rule answercall is active {
        select when twilio callstart
        {
          twilio:say("Thank you for your interest in buying Sam's Neo Freerunner");
  2. @TelegramSam TelegramSam revised this gist Oct 11, 2010. 1 changed file with 0 additions and 16 deletions.
    16 changes: 0 additions & 16 deletions NeoSale
    Original file line number Diff line number Diff line change
    @@ -20,22 +20,6 @@ ruleset a8x72 {
        dataset highbid <- "https://spreadsheets.google.com/pub?key=<redacted>&single=true&gid=1&range=B1&output=txt" cachable for 1 second;
        dataset winner <- "https://spreadsheets.google.com/pub?key=<redacted>&single=true&gid=1&range=B2&output=txt" cachable for 1 second;
      }

      rule phonedone is active {
        select when twilio callstart
        twilio:say("Bidding has ended with a final price of #{highbid} dollars. Thanks!");
    fired {
       last;
       }
      }

    rule smsdone is active {
          select when twilio sms
        twilio:sms("Bidding has ended with a final price of #{highbid} dollars. Thanks!");
    fired {
       last;
       }
      }

      rule first_rule is active {
        select when twilio callstart
  3. @TelegramSam TelegramSam created this gist Oct 11, 2010.
    143 changes: 143 additions & 0 deletions NeoSale
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,143 @@
    ruleset a8x72 {
      meta {
        name "NeoSale"
        description <<
          Selling the Neo Freerunner
        >>
        author "Sam Curren"
        logging on
        key twitter {
          "consumer_key" : "<redacted>",
          "consumer_secret" : "<redacted>",
          "oauth_token":"<redacted>",
          "oauth_token_secret":"<redacted>"
        }
      }

      dispatch {}

      global {
        dataset highbid <- "https://spreadsheets.google.com/pub?key=<redacted>&single=true&gid=1&range=B1&output=txt" cachable for 1 second;
        dataset winner <- "https://spreadsheets.google.com/pub?key=<redacted>&single=true&gid=1&range=B2&output=txt" cachable for 1 second;
      }

      rule phonedone is active {
        select when twilio callstart
        twilio:say("Bidding has ended with a final price of #{highbid} dollars. Thanks!");
    fired {
       last;
       }
      }

    rule smsdone is active {
          select when twilio sms
        twilio:sms("Bidding has ended with a final price of #{highbid} dollars. Thanks!");
    fired {
       last;
       }
      }

      rule first_rule is active {
        select when twilio callstart
        {
          twilio:say("Thank you for your interest in buying Sam's Neo Freerunner");
          twilio:pause(1);
          twilio:say("The current high bid is #{highbid} dollars.");
        }
        fired {
          raise explicit event getbid;
        }
      }

      rule getbid is active{
        select when explicit getbid or twilio getbid
        {
          twilio:gather_start("phonebid");
            twilio:say("Dial your bid in whole dollars. Hangup to not place a bid.");
          twilio:gather_stop();
          twilio:redirect("getbid");
        }
      }

      rule phonebid is active {
        select when twilio phonebid
        pre {
          bidvalue = event:param("Digits");
          bidder = event:param("Caller");
        }
        if bidvalue > highbid then {
          http:post("https://spreadsheets.google.com/formResponse?formkey=<redacted>") with
            params = {"entry.0.single":bidvalue, "entry.1.single":bidder, "submit":"Submit", "pageNumber":"0", "backupCache":""};
          twilio:say("Your bid of #{bidvalue} dollars has been placed. Thank you!");
        }
        fired {
          raise explicit event sendtweet with newmaxbid = bidvalue;
        } else {
          raise explicit event toolow;
        }
      }

      rule bidtoolow is active {
        select when explicit toolow
        {
          twilio:say("Your bid is below the current high bid of #{highbid} dollars.");
        }
        fired {
          raise explicit event getbid;
        }
      }

      rule sms is active {
        select when twilio sms
        pre {
          messagetext = event:param("Body");
          sender = event:param("From");
          bidlist = messagetext.extract(re/([0-9]+)/i);
        }
        if(bidlist.length() > 0) then {
            noop();
        }
        fired{
          raise explicit event smsbid with bidvalue = bidlist.head() and sender = sender;
        } else {
          raise explicit event smshelp;
        }
      }

      rule smsbid is active {
        select when explicit smsbid
        pre {
          bidder = event:param("sender");
          bidvalue = event:param("bidvalue");
        }
        if(bidvalue > highbid) then {
          http:post("https://spreadsheets.google.com/formResponse?formkey=<redacted>") with
            params = {"entry.0.single":bidvalue, "entry.1.single":bidder, "submit":"Submit", "pageNumber":"0", "backupCache":""};
          twilio:sms("Your bid of #{bidvalue} dollars has been placed. Thank you!");
        }
        fired {
          raise explicit event sendtweet with newmaxbid = bidvalue;
        } else {
          raise explicit event smslow;
        }
      }

      rule smslow is active {
        select when explicit smslow
        twilio:sms("Your bid is below the current high bid of $#{highbid}. Reply with 'bid x' to bid x dollars.");
      }

      rule smshelp is active {
        select when explicit smshelp
        twilio:sms("The current high bid for Sam's Neo FreeRunner is $#{highbid}. Reply with 'bid x' to bid x dollars.");
      }

      rule tweet is active {
        select when explicit sendtweet
        pre {
          newvalue = event:param("newmaxbid");
          tweet = "New Bid! I'm now being sold for $#{newvalue}. Call to Bid: 801.988.9331 #utosc";
        }
        twitter:update(tweet);
      }
    }