I have a zotonic site up and running and have successfully configured the twitter module to receive tweets as they are posted. What I would like to do now is update the website in realtime as the tweets are created, much like Disqus comments. Can someone give me some guidance on how to achieve this?
You could create a function *observe_rsc_update_done/2* in your module,
which is fired every time a rsc is updated (so also when tweets arrive).
You could then look at the *action* attribute of the #rsc_update_done
record to determine it's an insert, and look at the *post_is_a* attribute
to see if it's a *tweet*. If so, you can decide to do something...
On Mon, Oct 29, 2012 at 2:57 PM, tpbradley <t...@71squared.com> wrote:
> Hi all,
> I have a zotonic site up and running and have successfully configured the
> twitter module to receive tweets as they are posted. What I would like to
> do now is update the website in realtime as the tweets are created, much
> like Disqus comments. Can someone give me some guidance on how to achieve
> this?
Thanks got getting back to me. I think the *observe_rsc_update_done/2 *function is what I need to implement. I want to show a realtime twitter feed on my site but I'm unsure of how to achieve this. Am I right in thinking I should a new module that implements the *observe_rsc_update_done/2 *function and enable it in the module admin. Each user on the site would then be observing resource updates. To push an update out to the browser, do I call something like *z_session_page:add_script/2* in the * observe_rsc_update_done/2 *function?
On Monday, 29 October 2012 14:03:38 UTC, Arjan Scherpenisse wrote:
> What exactly do you want to update?
> You could create a function *observe_rsc_update_done/2* in your module, > which is fired every time a rsc is updated (so also when tweets arrive).
> You could then look at the *action* attribute of the #rsc_update_done > record to determine it's an insert, and look at the *post_is_a* attribute > to see if it's a *tweet*. If so, you can decide to do something...
> Arjan
> On Mon, Oct 29, 2012 at 2:57 PM, tpbradley <t...@71squared.com<javascript:> > > wrote:
>> Hi all,
>> I have a zotonic site up and running and have successfully configured the >> twitter module to receive tweets as they are posted. What I would like to >> do now is update the website in realtime as the tweets are created, much >> like Disqus comments. Can someone give me some guidance on how to achieve >> this?
You could use mod_signal to do a *mod_signal:emit/2* inside the rsc_update_done function, and then connect a wire to the signal on the page (or in the template) where you want the live stream to be.
> Thanks got getting back to me. I think the *observe_rsc_update_done/2 > *function is what I need to implement. I want to show a realtime > twitter feed on my site but I'm unsure of how to achieve this. Am I > right in thinking I should a new module that implements the > *observe_rsc_update_done/2 *function and enable it in the module > admin. Each user on the site would then be observing resource updates. > To push an update out to the browser, do I call something like > *z_session_page:add_script/2* in the *observe_rsc_update_done/2 *function?
> Thanks
> On Monday, 29 October 2012 14:03:38 UTC, Arjan Scherpenisse wrote:
> What exactly do you want to update?
> You could create a function *observe_rsc_update_done/2* in your
> module, which is fired every time a rsc is updated (so also when
> tweets arrive).
> You could then look at the *action* attribute of the
> #rsc_update_done record to determine it's an insert, and look at
> the *post_is_a* attribute to see if it's a /tweet/. If so, you can
> decide to do something...
> Arjan
> On Mon, Oct 29, 2012 at 2:57 PM, tpbradley <t...@71squared.com
> <javascript:>> wrote:
> Hi all,
> I have a zotonic site up and running and have successfully
> configured the twitter module to receive tweets as they are
> posted. What I would like to do now is update the website in
> realtime as the tweets are created, much like Disqus comments.
> Can someone give me some guidance on how to achieve this?
mod_signal looks like just what I need, thanks! I've had a little play and now have my own module thats observing resource changes and calling off to *mod_signal:emit/2 *however, my web page is not receiving the events. I've found that the admin pages inject some javascript that hooks up the event
For some reason, my site doesn't inject any javascript registering for the twitter_update event. The following is the JS generated at the bottom of my site page.
> You could use mod_signal to do a *mod_signal:emit/2* inside the > rsc_update_done function, and then connect a wire to the signal on the page > (or in the template) where you want the live stream to be.
> That should do the trick... > In the arguments of the emit you can even pass in the id of the newly > created tweet so your template can show it.
> Let us know if this works for you!
> Arjan
> On 10/29/2012 03:40 PM, tpbradley wrote:
> Hi Arjan,
> Thanks got getting back to me. I think the *observe_rsc_update_done/2 *function > is what I need to implement. I want to show a realtime twitter feed on my > site but I'm unsure of how to achieve this. Am I right in thinking I should > a new module that implements the *observe_rsc_update_done/2 *function and > enable it in the module admin. Each user on the site would then be > observing resource updates. To push an update out to the browser, do I call > something like *z_session_page:add_script/2* in the * > observe_rsc_update_done/2 *function?
> Thanks
> On Monday, 29 October 2012 14:03:38 UTC, Arjan Scherpenisse wrote:
>> What exactly do you want to update?
>> You could create a function *observe_rsc_update_done/2* in your module, >> which is fired every time a rsc is updated (so also when tweets arrive).
>> You could then look at the *action* attribute of the #rsc_update_done >> record to determine it's an insert, and look at the *post_is_a* attribute >> to see if it's a *tweet*. If so, you can decide to do something...
>> Arjan
>> On Mon, Oct 29, 2012 at 2:57 PM, tpbradley <t...@71squared.com> wrote:
>>> Hi all,
>>> I have a zotonic site up and running and have successfully configured >>> the twitter module to receive tweets as they are posted. What I would like >>> to do now is update the website in realtime as the tweets are created, much >>> like Disqus comments. Can someone give me some guidance on how to achieve >>> this?
Do you add the {% wire %} in your template with the action={connect...} attribute?
That should be enough.
And of course your template should include the "usual" scripts like in the base template, a lib with zotonic-1.0.js, {% stream %} and {% script %}, iirc
> mod_signal looks like just what I need, thanks! I've had a little play > and now have my own module thats observing resource changes and > calling off to *mod_signal:emit/2 *however, my web page is not > receiving the events. I've found that the admin pages inject some > javascript that hooks up the event
> For some reason, my site doesn't inject any javascript registering for > the twitter_update event. The following is the JS generated at the > bottom of my site page.
> You could use mod_signal to do a *mod_signal:emit/2* inside the
> rsc_update_done function, and then connect a wire to the signal on
> the page (or in the template) where you want the live stream to be.
> That should do the trick...
> In the arguments of the emit you can even pass in the id of the
> newly created tweet so your template can show it.
> Let us know if this works for you!
> Arjan
> On 10/29/2012 03:40 PM, tpbradley wrote:
>> Hi Arjan,
>> Thanks got getting back to me. I think the
>> *observe_rsc_update_done/2 *function is what I need to implement.
>> I want to show a realtime twitter feed on my site but I'm unsure
>> of how to achieve this. Am I right in thinking I should a new
>> module that implements the *observe_rsc_update_done/2 *function
>> and enable it in the module admin. Each user on the site would
>> then be observing resource updates. To push an update out to the
>> browser, do I call something like *z_session_page:add_script/2*
>> in the *observe_rsc_update_done/2 *function?
>> Thanks
>> On Monday, 29 October 2012 14:03:38 UTC, Arjan Scherpenisse wrote:
>> What exactly do you want to update?
>> You could create a function *observe_rsc_update_done/2* in
>> your module, which is fired every time a rsc is updated (so
>> also when tweets arrive).
>> You could then look at the *action* attribute of the
>> #rsc_update_done record to determine it's an insert, and look
>> at the *post_is_a* attribute to see if it's a /tweet/. If so,
>> you can decide to do something...
>> Arjan
>> On Mon, Oct 29, 2012 at 2:57 PM, tpbradley
>> <t...@71squared.com> wrote:
>> Hi all,
>> I have a zotonic site up and running and have
>> successfully configured the twitter module to receive
>> tweets as they are posted. What I would like to do now is
>> update the website in realtime as the tweets are created,
>> much like Disqus comments. Can someone give me some
>> guidance on how to achieve this?
Yea thats the weird thing, I do have a {% wire %} along with the {% stream %} and {% script %} commands and all the JS. I've tried adding html around the scomps to verify the template is updating correctly. I've also cleared the cache and rescanned all modules just in case ;)
On Tuesday, 30 October 2012 07:17:45 UTC, Arjan Scherpenisse wrote:
> Do you add the {% wire %} in your template with the action={connect...} > attribute?
> That should be enough.
> And of course your template should include the "usual" scripts like in the > base template, a lib with zotonic-1.0.js, {% stream %} and {% script %}, > iirc
> Arjan
> On 10/29/2012 09:07 PM, tpbradley wrote:
> Hi Arjan,
> mod_signal looks like just what I need, thanks! I've had a little play > and now have my own module thats observing resource changes and calling off > to *mod_signal:emit/2 *however, my web page is not receiving the events. > I've found that the admin pages inject some javascript that hooks up the > event
> For some reason, my site doesn't inject any javascript registering for > the twitter_update event. The following is the JS generated at the bottom > of my site page.
>> You could use mod_signal to do a *mod_signal:emit/2* inside the >> rsc_update_done function, and then connect a wire to the signal on the page >> (or in the template) where you want the live stream to be.
>> That should do the trick...
>> In the arguments of the emit you can even pass in the id of the newly >> created tweet so your template can show it.
>> Let us know if this works for you!
>> Arjan
>> On 10/29/2012 03:40 PM, tpbradley wrote:
>> Hi Arjan,
>> Thanks got getting back to me. I think the *observe_rsc_update_done/2 *function >> is what I need to implement. I want to show a realtime twitter feed on my >> site but I'm unsure of how to achieve this. Am I right in thinking I should >> a new module that implements the *observe_rsc_update_done/2 *function >> and enable it in the module admin. Each user on the site would then be >> observing resource updates. To push an update out to the browser, do I call >> something like *z_session_page:add_script/2* in the *
>> observe_rsc_update_done/2 *function?
>> Thanks
>> On Monday, 29 October 2012 14:03:38 UTC, Arjan Scherpenisse wrote:
>>> What exactly do you want to update?
>>> You could create a function *observe_rsc_update_done/2* in your >>> module, which is fired every time a rsc is updated (so also when tweets >>> arrive).
>>> You could then look at the *action* attribute of the #rsc_update_done >>> record to determine it's an insert, and look at the *post_is_a* attribute >>> to see if it's a *tweet*. If so, you can decide to do something...
>>> Arjan
>>> On Mon, Oct 29, 2012 at 2:57 PM, tpbradley <t...@71squared.com> wrote:
>>>> Hi all,
>>>> I have a zotonic site up and running and have successfully configured >>>> the twitter module to receive tweets as they are posted. What I would like >>>> to do now is update the website in realtime as the tweets are created, much >>>> like Disqus comments. Can someone give me some guidance on how to achieve >>>> this?
> Yea thats the weird thing, I do have a {% wire %} along with the {% > stream %} and {% script %} commands and all the JS. I've tried adding > html around the scomps to verify the template is updating correctly. > I've also cleared the cache and rescanned all modules just in case ;)
> If you examine the page at http://71squared.com:8000 you can see the > js files are being included
> Below is the contents of my base.tpl file
> Cheers
> {% all include "_html_body.tpl" %}
> </body>
> </html>
> On Tuesday, 30 October 2012 07:17:45 UTC, Arjan Scherpenisse wrote:
> Do you add the {% wire %} in your template with the
> action={connect...} attribute?
> That should be enough.
> And of course your template should include the "usual" scripts
> like in the base template, a lib with zotonic-1.0.js, {% stream %}
> and {% script %}, iirc
> Arjan
> On 10/29/2012 09:07 PM, tpbradley wrote:
>> Hi Arjan,
>> mod_signal looks like just what I need, thanks! I've had a little
>> play and now have my own module thats observing resource changes
>> and calling off to *mod_signal:emit/2 *however, my web page is
>> not receiving the events. I've found that the admin pages inject
>> some javascript that hooks up the event
>> For some reason, my site doesn't inject any javascript
>> registering for the twitter_update event. The following is the JS
>> generated at the bottom of my site page.
>> You could use mod_signal to do a *mod_signal:emit/2* inside
>> the rsc_update_done function, and then connect a wire to the
>> signal on the page (or in the template) where you want the
>> live stream to be.
>> That should do the trick...
>> In the arguments of the emit you can even pass in the id of
>> the newly created tweet so your template can show it.
>> Let us know if this works for you!
>> Arjan
>> On 10/29/2012 03:40 PM, tpbradley wrote:
>>> Hi Arjan,
>>> Thanks got getting back to me. I think the
>>> *observe_rsc_update_done/2 *function is what I need to
>>> implement. I want to show a realtime twitter feed on my site
>>> but I'm unsure of how to achieve this. Am I right in
>>> thinking I should a new module that implements the
>>> *observe_rsc_update_done/2 *function and enable it in the
>>> module admin. Each user on the site would then be observing
>>> resource updates. To push an update out to the browser, do I
>>> call something like *z_session_page:add_script/2* in the
>>> *observe_rsc_update_done/2 *function?
>>> Thanks
>>> On Monday, 29 October 2012 14:03:38 UTC, Arjan Scherpenisse
>>> wrote:
>>> What exactly do you want to update?
>>> You could create a function
>>> *observe_rsc_update_done/2* in your module, which is
>>> fired every time a rsc is updated (so also when tweets
>>> arrive).
>>> You could then look at the *action* attribute of the
>>> #rsc_update_done record to determine it's an insert, and
>>> look at the *post_is_a* attribute to see if it's a
>>> /tweet/. If so, you can decide to do something...
>>> Arjan
>>> On Mon, Oct 29, 2012 at 2:57 PM, tpbradley
>>> <t...@71squared.com> wrote:
>>> Hi all,
>>> I have a zotonic site up and running and have
>>> successfully configured the twitter module to
>>> receive tweets as they are posted. What I would like
>>> to do now is update the website in realtime as the
>>> tweets are created, much like Disqus comments. Can
>>> someone give me some guidance on how to achieve this?
note that the arguments in the /connect/ action function as filters: so in the example, only a growl is triggered when the signal is *example***/and/ the argument has a {*session, 123*} tuple.
> Yea thats the weird thing, I do have a {% wire %} along with the {% > stream %} and {% script %} commands and all the JS. I've tried adding > html around the scomps to verify the template is updating correctly. > I've also cleared the cache and rescanned all modules just in case ;)
> If you examine the page at http://71squared.com:8000 you can see the > js files are being included
> Below is the contents of my base.tpl file
> Cheers
> {% all include "_html_body.tpl" %}
> </body>
> </html>
> On Tuesday, 30 October 2012 07:17:45 UTC, Arjan Scherpenisse wrote:
> Do you add the {% wire %} in your template with the
> action={connect...} attribute?
> That should be enough.
> And of course your template should include the "usual" scripts
> like in the base template, a lib with zotonic-1.0.js, {% stream %}
> and {% script %}, iirc
> Arjan
> On 10/29/2012 09:07 PM, tpbradley wrote:
>> Hi Arjan,
>> mod_signal looks like just what I need, thanks! I've had a little
>> play and now have my own module thats observing resource changes
>> and calling off to *mod_signal:emit/2 *however, my web page is
>> not receiving the events. I've found that the admin pages inject
>> some javascript that hooks up the event
>> For some reason, my site doesn't inject any javascript
>> registering for the twitter_update event. The following is the JS
>> generated at the bottom of my site page.
>> You could use mod_signal to do a *mod_signal:emit/2* inside
>> the rsc_update_done function, and then connect a wire to the
>> signal on the page (or in the template) where you want the
>> live stream to be.
>> That should do the trick...
>> In the arguments of the emit you can even pass in the id of
>> the newly created tweet so your template can show it.
>> Let us know if this works for you!
>> Arjan
>> On 10/29/2012 03:40 PM, tpbradley wrote:
>>> Hi Arjan,
>>> Thanks got getting back to me. I think the
>>> *observe_rsc_update_done/2 *function is what I need to
>>> implement. I want to show a realtime twitter feed on my site
>>> but I'm unsure of how to achieve this. Am I right in
>>> thinking I should a new module that implements the
>>> *observe_rsc_update_done/2 *function and enable it in the
>>> module admin. Each user on the site would then be observing
>>> resource updates. To push an update out to the browser, do I
>>> call something like *z_session_page:add_script/2* in the
>>> *observe_rsc_update_done/2 *function?
>>> Thanks
>>> On Monday, 29 October 2012 14:03:38 UTC, Arjan Scherpenisse
>>> wrote:
>>> What exactly do you want to update?
>>> You could create a function
>>> *observe_rsc_update_done/2* in your module, which is
>>> fired every time a rsc is updated (so also when tweets
>>> arrive).
>>> You could then look at the *action* attribute of the
>>> #rsc_update_done record to determine it's an insert, and
>>> look at the *post_is_a* attribute to see if it's a
>>> /tweet/. If so, you can decide to do something...
>>> Arjan
>>> On Mon, Oct 29, 2012 at 2:57 PM, tpbradley
>>> <t...@71squared.com> wrote:
>>> Hi all,
>>> I have a zotonic site up and running and have
>>> successfully configured the twitter module to
>>> receive tweets as they are posted. What I would like
>>> to do now is update the website in realtime as the
>>> tweets are created, much like Disqus comments. Can
>>> someone give me some guidance on how to achieve this?
Ahhhh, looks like it is all working as expected.... I've just noticed that the growl notifications are displaying at the bottom of the page, so you have to scroll down to see them. I must have a CSS issue somewhere! Thanks for all the help! This signal stuff is awesome!!
A couple of quick questions...
1. How would I go about calling emit from the zotonic shell? I've tried copying in the erlang code as follows but Context is undefined.
2. While I was in the zotonic shell, I noticed some error messages being emitted from the twitter module, which I've just realised is because I have multiple sites pointing at the same database. I will remove these soon which should fix the problem, but thought it was worth mentioning in case a fix could be put in, or better logging of the errors.
17:56:42.322 [info] Twitter: (blogtest) Username = "71squared"
17:56:42.369 [info] Twitter: (admin) Username = "71squared"
17:56:43.061 [info] Twitter: (ssquared) Username = "71squared"
17:56:52.414 [error] Twitter: unknown stream result ({{"HTTP/1.1",420,"Client Error (420)"},[{"content-length","67"},{"content-type","text/html"}],<<"Easy there, Turbo. Too many requests recently. Enhance your calm.\r\n">>})
17:56:52.482 [error] Twitter: unknown stream result ({{"HTTP/1.1",420,"Client Error (420)"},[{"content-length","67"},{"content-type","text/html"}],<<"Easy there, Turbo. Too many requests recently. Enhance your calm.\r\n">>})
17:56:53.149 [error] Twitter: unknown stream result ({{"HTTP/1.1",420,"Client Error (420)"},[{"content-length","67"},{"content-type","text/html"}],<<"Easy there, Turbo. Too many requests recently. Enhance your calm.\r\n">>})
> note that the arguments in the *connect* action function as filters: so > in the example, only a growl is triggered when the signal is *example** **
> and* the argument has a {*session, 123*} tuple.
> On 10/30/2012 01:04 PM, tpbradley wrote:
> Yea thats the weird thing, I do have a {% wire %} along with the {% stream > %} and {% script %} commands and all the JS. I've tried adding html around > the scomps to verify the template is updating correctly. I've also cleared > the cache and rescanned all modules just in case ;)
> If you examine the page at http://71squared.com:8000 you can see the js > files are being included
> Below is the contents of my base.tpl file > Cheers
> {% all include "_html_body.tpl" %}
> </body>
> </html>
> On Tuesday, 30 October 2012 07:17:45 UTC, Arjan Scherpenisse wrote:
>> Do you add the {% wire %} in your template with the action={connect...} >> attribute?
>> That should be enough.
>> And of course your template should include the "usual" scripts like in >> the base template, a lib with zotonic-1.0.js, {% stream %} and {% script >> %}, iirc
>> Arjan
>> On 10/29/2012 09:07 PM, tpbradley wrote:
>> Hi Arjan,
>> mod_signal looks like just what I need, thanks! I've had a little play >> and now have my own module thats observing resource changes and calling off >> to *mod_signal:emit/2 *however, my web page is not receiving the events. >> I've found that the admin pages inject some javascript that hooks up the >> event
>> For some reason, my site doesn't inject any javascript registering for >> the twitter_update event. The following is the JS generated at the bottom >> of my site page.
>>> You could use mod_signal to do a *mod_signal:emit/2* inside the >>> rsc_update_done function, and then connect a wire to the signal on the page >>> (or in the template) where you want the live stream to be.
>>> That should do the trick...
>>> In the arguments of the emit you can even pass in the id of the newly >>> created tweet so your template can show it.
>>> Let us know if this works for you!
>>> Arjan
>>> On 10/29/2012 03:40 PM, tpbradley wrote:
>>> Hi Arjan,
>>> Thanks got getting back to me. I think the *observe_rsc_update_done/2 *function >>> is what I need to implement. I want to show a realtime twitter feed on my >>> site but I'm unsure of how to achieve this. Am I right in thinking I should >>> a new module that implements the *observe_rsc_update_done/2 *function >>> and enable it in the module admin. Each user on the site would then be >>> observing resource updates. To push an update out to the browser, do I call >>> something like *z_session_page:add_script/2* in the *
>>> observe_rsc_update_done/2 *function?
>>> Thanks
>>> On Monday, 29 October 2012 14:03:38 UTC, Arjan Scherpenisse wrote:
>>>> What exactly do you want to update?
>>>> You could create a function *observe_rsc_update_done/2* in your >>>> module, which is fired every time a rsc is updated (so also when tweets >>>> arrive).
>>>> You could then look at the *action* attribute of the #rsc_update_done >>>> record to determine it's an insert, and look at the *post_is_a* attribute >>>> to see if it's a *tweet*. If so, you can decide to do something...
>>>> Arjan
>>>> On Mon, Oct 29, 2012 at 2:57 PM, tpbradley <t...@71squared.com> wrote:
>>>>> Hi all,
>>>>> I have a zotonic site up and running and have successfully >>>>> configured the twitter module to receive tweets as they are posted. What I >>>>> would like to do now is update the website in realtime as the tweets are >>>>> created, much like Disqus comments. Can someone give me some guidance on >>>>> how to achieve this?
> 17:56:53.149 [error] Twitter: unknown stream result > ({{"HTTP/1.1",420,"Client Error > (420)"},[{"content-length","67"},{"content-type","text/html"}],<<"Easy > there, Turbo. Too many requests recently. Enhance your calm.\r\n">>})
Twitter allows only one connection per user on the streaming API. It will disconnect the previous connection in case of multiple connections per user.
When you have multiple sites on a single DB, then the twitter module is started for each of those sites, using the same credentials, so that means that the twitter modules start fighting for the connections because they keep reconnecting, resulting in the /Easy there, Turbo/ message... Not much to fix there, I'd just make a separate DB for each site. Or try using a single db with multiple schemas per site...
On Tuesday, October 30, 2012 8:26:45 PM UTC, Arjan Scherpenisse wrote:
> On 10/30/2012 07:16 PM, tpbradley wrote:
> 17:56:53.149 [error] Twitter: unknown stream result > ({{"HTTP/1.1",420,"Client Error > (420)"},[{"content-length","67"},{"content-type","text/html"}],<<"Easy > there, Turbo. Too many requests recently. Enhance your calm.\r\n">>})
> Twitter allows only one connection per user on the streaming API. It will > disconnect the previous connection in case of multiple connections per user.
> When you have multiple sites on a single DB, then the twitter module is > started for each of those sites, using the same credentials, so that means > that the twitter modules start fighting for the connections because they > keep reconnecting, resulting in the *Easy there, Turbo* message... Not > much to fix there, I'd just make a separate DB for each site. Or try using > a single db with multiple schemas per site...