Configuration
Before starting the project, there are a few things that need to be configured, such as session storage backend, USSD gateway, and pagination.
Session storage
Ananse supports several backends for storing user sessions - in memory, Redis, MySQL and Postgres. In-memory session storage is used by default but can be changed to another backend. The session storage can be configured using the session
option in the configure
method.
import { Ananse } from "ananse";
const ananse = new Ananse().configure({
session: { type: "redis" }, // Database to store session data. Eg. mysql, postgres and redis
...
});
export default ananse;
Below is a list of supported session storage backends:
memory
- In-memory session storageredis
- Redis session storagemysql
- MySQL session storagepostgres
- Postgres session storage
Refer to session storage guide on how to create a custom session storage.
USSD Gateway
Ananse can be configured to support any USSD gateway. The USSD gateway to use can be configured using the gateway
option in the configure
method.
const ananse = new Ananse().configure({
gateway: "hubtel", // USSD gateway to use, eg. hubtel, africas_talking.
...
});
Below is a list of supported USSD gateways:
Gateway | Key | Supported |
---|---|---|
Wigal USSD v1 | wigal | ✅ |
Wigal USSD v2 | ❌ | |
Emergent Technology USSD | emergent_technology | ✅ |
AfricasTalking USSD | ❌ |
Is your USSD gateway not supported? Feel free to open an issue or create a pull request to add support for it.
Middlewares
Ananse supports middleware, which are custom classes, that can access the request and response object in the application’s request-response cycle. The USSD gateways are implemented as middleware classes. Middleware can perform the following tasks:
- Execute any code.
- Make changes to the request and the response objects.
- End the request-response cycle.
Middleware can be added to the application using the middlewares
option in the configure
method.
const ananse = new Ananse().configure({
middlewares: [MyCustomGateway, MyOtherMiddleware],
...
});
The order in which middleware are added is important. Middleware are executed in the order they are added.
Pagination
Pagination is enabled by default, it is triggered if the menu content exceeds the *182 character limit. Set the enabled
option to false
to disable pagination. The navigation options can be configured using the pagination
option in the configure
method.
const ananse = new Ananse().configure({
pagination: {
enabled: true,
nextPage: {
display: "*. More",
choice: "*",
},
previousPage: {
display: "#. Back",
choice: "#",
},
},
...
});