response from bot

Help and bugs.

response from bot

Postby jawaria » May 23rd, 2012, 5:48 pm

hey there!
is there anyway in which a bot can itself send a message after some predefined time ! like if user does not respond for let say 5 mins the bot display msgs like "hellooo?" , "u there".
jawaria
Regular Member
 
Posts: 25
Joined: March 25th, 2012, 6:50 pm

Re: response from bot

Postby jawaria » May 24th, 2012, 8:52 am

i am trying to use settimeout function
at index page i did this

function timeout_trigger() {
window.alert('say something!');
}
if(!isset($_POST['SAY']))
{
setTimeout('timeout_trigger()', 2000);
}
but this is not working .
jawaria
Regular Member
 
Posts: 25
Joined: March 25th, 2012, 6:50 pm

Re: response from bot

Postby GeekCaveCreations » May 28th, 2012, 2:14 am

Well, for one thing, you're mixing PHP and JavaScript, which can be tricky, even in the best of times. It's better if you use straight JavaScript for this, because the PHP portion of the page only runs once, while the page is being "built". What you can try here is setting a variable for the current timestamp each time the page loads, and compare that value to the current timestamp in the timeout_trigger() function. If the difference between the two timestamp values is greater than a set amount of time, then trigger the alert. The code for something like that would look like this:

Code: Select all
<script type="text/javascript">
  var curTime = new Date();
  var pageLoad = curTime.getTime(); // This is a UTC timestamp, in milliseconds, indicating the current time
  var threeMinutes = 60 * 3 * 1000; //180 seconds, or 3 minutes, in milliseconds
// Other code here
  function timeZone_trigger() {
    var rawNow = new Date();
    var now = rawNow.getTime();
    var elapsedTime = now - pageLoad; // This is the time from when the page loaded until now, in milliseconds (i.e. the elapsed time)
    if (elapsedTime > threeMinutes) {
      alert('Say something!');
      // do something here
    }
  }
  // Other JavaScript code here
  setTimeout('timeout_trigger()', 2000);
</script>
Comforting the disturbed, and disturbing the comfortable
Chat with Morti
User avatar
GeekCaveCreations
Safe, Reliable Insanity, Since 1961
 
Posts: 1115
Joined: April 18th, 2011, 10:52 pm
Location: Nevada, USA

Re: response from bot

Postby jawaria » May 28th, 2012, 6:23 pm

thanks alot :) i tried this code with tiny modifications i am posting it here so that i t can b help of anyone who wants the same thing done!
Code: Select all
<script type="text/javascript">
  var curTime = new Date();
  var pageLoad = curTime.getTime(); //This is a UTC timestamp, in milliseconds, indicating the current time
  var threeMinutes = 60 * 3 * 1000; //180 seconds, or 3 minutes, in milliseconds
  function timeout_trigger()
  {
    var rawNow = new Date();
    var now = rawNow.getTime();
    var elapsedTime = now - pageLoad; // This is the time from when the page loaded until now, in milliseconds (i.e. the elapsed time)
    if (elapsedTime > threeMinutes)
   {
     pageLoad=now; // to detect everytime the user is idle
      alert('Say something!');
    }
  }
   setInterval('timeout_trigger()', 2000); // to check the status after every 2sec
   
  </script>
jawaria
Regular Member
 
Posts: 25
Joined: March 25th, 2012, 6:50 pm

Re: response from bot

Postby programo » June 1st, 2012, 3:14 pm

Nice one.... a lot of people will love that
:D
User avatar
programo
Site Admin
 
Posts: 306
Joined: April 4th, 2011, 4:46 pm
Location: Nottingham UK

Re: response from bot

Postby voarsh » June 10th, 2012, 12:44 pm

This is useful, but would this JUST be a javascript alert, or will the bot say this?


Where would I put this code?
voarsh
Obsessed Member
 
Posts: 114
Joined: March 12th, 2012, 8:59 pm

Re: response from bot

Postby GeekCaveCreations » June 10th, 2012, 1:41 pm

Since this is done using JavaScript, and since it's done client-side, the only way to have the bot "say" something is through an alert() message. Now, that said, if you're using an AJAX interface (tricky with version 1, but not impossible), you can insert just about anything you like into the conversation stream, just as if the bot said it, neatly doing away with the need to use an alert(). In fact, if the interface page is AJAX driven, you can do a whole bunch more, like load a different avatar image (if there is one), to simulate the bot's impatience, play a sound, shake the screen, and a whole range of other things to get the user's attention. The possibilities are only limited to the imagination.
Comforting the disturbed, and disturbing the comfortable
Chat with Morti
User avatar
GeekCaveCreations
Safe, Reliable Insanity, Since 1961
 
Posts: 1115
Joined: April 18th, 2011, 10:52 pm
Location: Nevada, USA

Re: response from bot

Postby voarsh » June 10th, 2012, 2:47 pm

These are great ideas!!

Thanks, unfortunately, I don't know where I'd put these changes within the files, I am also NOT a PHP programmer.

:(
voarsh
Obsessed Member
 
Posts: 114
Joined: March 12th, 2012, 8:59 pm

Re: response from bot

Postby Boardtalk » June 10th, 2012, 5:45 pm

Put it below the </head> and after the time specified a popup window opens with the message and the user clicks 'OK' to continue.
Boardtalk
Avid Member
 
Posts: 57
Joined: July 29th, 2011, 2:00 pm


Return to Bugs and Help

Who is online

Users browsing this forum: No registered users and 1 guest

cron