3

I need to receive an email notification whenever a user creates a ticket or a ticket gets updated. Fossil has something called ticket hook, which is accessible in the UI from admin -> transfers -> Ticket. I have tried the following code from here:

set project simpletask
tclInvoke package require http
query {SELECT title, status
        FROM ticket
        WHERE tkt_uuid=$uuid} {
   set title [tclInvoke http::formatQuery  $title]
   http -asynchronous -- http://127.0.0.1/cgi-bin/tkt-hook?uuid=$uuid&title=$title&status=$status&project=$project
}

I expect this code to be executed once a ticket is modified, but I don't really know how to modify it to send an email, and how I can specify to whom the email should be sent to.

Does anyone have a sample TH1 code for sending email notifications that can share?

Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
Ari
  • 7,251
  • 11
  • 40
  • 70

2 Answers2

4

TH1 is not able to do this on its own; it's too limited (and deliberately so). If you've got invocation of Tcl enabled in TH1 (it's not enabled by default) then you can use something like:

### THIS IS TH1 ###
tclInvoke source /some/dir/scripts/emailsender.tcl
query {SELECT title, status
       FROM ticket
       WHERE tkt_uuid=$uuid} {
    tclInvoke send_email $title $status $uuid
}

Then you just need to make sure that your emailsender.tcl script (in the above location) defines a procedure send_email that does what you want. You're talking about something like this:

### THIS IS TCL ###
package require mime
package require smtp

# Where to route messages through; IMPORTANT!
variable smtp_host smtp.example.com

proc send_email {title status uuid} {
    variable smtp_host
    set t [mime::initialize -canonical text/plain \
            -string "state is now $status for $uuid"]
    mime::setheader $t Subject "Change to '$title'"
    smtp::sendmessage $t -recipients you@example.com -servers $smtp_host
    mime::finalize $t
}

You'll need to pass across more fields, insert more logic to generate a message, choose who to send the message to (a mailing list is a good start!) and so on, but that's the core of it all. You may also need to explicitly lappend the directory containing the Tcllib packages to the global auto_path; that script is going to be very specific to your configuration.


Or you could make a script that listens to that port you push a notification to using the sample script and work with that. That would be easier to abuse though; not recommended.

Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
  • @Donald Fellows: Your solution should work, but I have problem with auto_path. I have tried either of: `set auto_path [linsert $auto_path 0 /pathtotcllib/]` and `lappend auto_path [file join $env(HOME) /pathtotcllib/]` – Ari May 21 '14 at 18:49
0

I just followed IFTTT approach, where we used IFTTT service to connect rss feed of Fossil scm to Gmail channel. It worked.

Please refer: http://lists.fossil-scm.org:8080/pipermail/fossil-users/2013-August/013330.html https://ifttt.com/recipes/109526

https://ifttt.com/recipes/109526 --> is for email notification for New ticket, that can be modified (change keyword or simple phrase) to send email for any ticket modification.

charybr
  • 1,888
  • 24
  • 29