HTTP API Conversation Client¶
-
class
go_http.send.
HttpApiSender
(account_key, conversation_key, conversation_token, api_url=None, session=None)¶ A helper for sending text messages and firing metrics via Vumi Go’s HTTP API.
Parameters: - account_key (str) – The unique id of the account to send to. You can find this at the bottom of the Account > Details page in Vumi Go.
- conversation_key (str) – The unique id of the conversation to send to. This is the UUID at the end of the conversation URL.
- conversation_token (str) – The secret authentication token entered in the conversation config.
- api_url (str) – The full URL of the HTTP API. Defaults to
https://go.vumi.org/api/v1/go/http_api_nostream
. - session (
requests.Session
) – Requests session to use for HTTP requests. Defaults to a new session.
-
fire_metric
(metric, value, agg='last')¶ Fire a value for a metric.
Parameters: - metric (str) – Name of the metric to fire.
- value (float) – Value for the metric.
- agg (str) – Aggregation type. Defaults to
'last'
. Other allowed values are'sum'
,'avg'
,'max'
and'min'
.
Note that metrics can also be fired via the metrics API. See
go_http.metrics.MetricsApiClient.fire()
.
-
send_text
(to_addr, content, session_event=None)¶ Send a text message to an address.
Parameters: - to_addr (str) – Address to send to.
- content (str) – Text to send.
- session_event (str) – The session event for session-based messaging channels (e.g. USSD). May be one of ‘new’, ‘resume’ or ‘close’. Optional.
-
send_voice
(to_addr, content, speech_url=None, wait_for=None, session_event=None)¶ Send a voice message to an address.
Parameters: - to_addr (str) – Address to send to.
- content (str) – Text to send. If
speech_url
is not provided, a text-to-speech engine is used to generate a voice message from this text. Ifspeech_url
is provided, this text is ignored by voice messaging channels, but may still be used by non-voice channels that process the message. - speech_url (str) – A URL to a voice file containing the voice message to sent.
If not given, a voice message is generated from
content
using a text-to-speech engine. Optional. - wait_for (str) – By default the Vumi voice connections send a response to a
message as soon as a key is pressed by the person the call is with.
The
wait_for
option allows specifying a character to wait for before a response is returned. For example, withoutwait_for
pressing ‘123#’ on the phone would result in four response messages containing ‘1’, ‘2’, ‘3’ and ‘#’ respectively. Ifwait_for='#'
was set, pressing ‘123#’ would result in a single response message containing ‘123’. Optional. - session_event (str) – The session event. May be one of ‘new’, ‘resume’ or ‘close’.
‘new’ initiates a new call. ‘resume’ continues an existing call.
‘close’ ends an existing call. The default of
None
is equivalent to ‘resume’.