Synchronous mode

When you send a message in synchronous mode with Pushback's API , it'll hold the connection open (long-polling) until a user replies to the message.

Example of sync mode with a terminal and phone

To use synchronous mode, change the API endpoint from send to send_sync. The full API endpoint for sync mode is Refer to Getting Started) for code examples.

Caution: Since network conditions are unreliable, a synchronous connection can't be garanteed. In order to get reliable replies from messages consider using Webhooks.

Pushback does its best to maintain the connection for about 24 hours.

Example: Bash Workout Tracker

Here's an example of how to make a workout tracker in bash.

export PUSHBACK_TOKEN=<token>
export PUSHBACK_CHANNEL=<channel id>
curl -s \
  -d 'title=Workout time' \
  -d 'body=Its time to start your workout' \
  -d 'action1=Start' \
  | xargs -I {} bash -c 'if [[ "Start" == "{}" ]]; then
    sleep $WORKOUT_DURATION && curl -s \
      -u $PUSHBACK_TOKEN: \
      -d "id=$PUSHBACK_CHANNEL" \
      -d "title=Workout finished" \
      -d "body=Great job, you worked out for $WORKOUT_DURATION"

The first curl will send a message with an action Start.

Message is sent with an action

We were ready to workout so we pressed Start on the notification. The first curl receives the response Start as plain-text. We can use xargs to pipe the response into another bash script that will sleep 10 seconds, then send another message.

Message is sent after 10 seconds

Whew, what a workout!