---
# System prepended metadata

title: Consultation via Whatsapp

---

# Consultation via Whatsapp

- Chatbot
- `Tanya` -> flow qiscus

## RG's Proposal
```plantuml
wabiz -> chatbot: Kelas 1 SMP
chatbot -> chatbot: <record siswa = kelas 1 SMP>
chatbot -> wabiz: Mau tanya apa?

wabiz -> chatbot: Tanya
chatbot -> qiscus: {Message: "Tanya", command-extra: <biologi+smp>}
qiscus -> teacher: <Assign ke teacher yang jago Biologi>
teacher -> qiscus: <ambil conversation>
qiscus -> chatbot: 
chatbot -> chatbot: record start conversation

wabiz -> chatbot: Berapa luas lingkaran?
chatbot -> qiscus: Berapa luas lingkaran?
teacher -> qiscus: Jari2 dikali r kuadrat
qiscus --> wabiz: ini dipotong, webhook Qiscus diarahkan ke chatbot
qiscus -> chatbot: <proposal>
chatbot -> chatbot: <record teacherID>
chatbot -> wabiz: <proposal>

teacher -> qiscus: <end conversation>
qiscus -> chatbot: <end conversation (agentEmail)>
chatbot -> chatbot: <record end conversation>

```

**Qiscus Note**
- Proposal RG possible untuk dilakukan
- Bisa mendapatkan TeacherID (agent_id)
- Mengimplementasikan Custom channel (https://documentation.qiscus.com/multichannel-customer-service/customization#custom-channel)
- Ada intermediary service diantara Chatbot & Qiscus 
  - Tidak memerlukan integrasi Whatsapp channel
  - Drawbacks 
    - Whatsapp feature tidak dapat digunakan (misal: Outbound message, HSM 24 hours)
    - Perlu handle terkait HSM 24 Hours
- Mengimplementasikan Custom Agent allocation untuk assgin agent based on Division (https://documentation.qiscus.com/multichannel-customer-service/customization#custom-agent-allocation)
 - Custom channel yang akan allocate Agent dengan data yang didapat dari Chatbot (comment extra: mapel+kelas, room_id)

## Qiscus' Proposal
```plantuml
wabiz -> qiscus
qiscus -> chatbot: webhook (can have agentID payload)
chatbot --> qiscus: reply (in HTTP response)
qiscus --> wabiz
```
**Qiscus Note**
- Common implementation dari Qiscus
- Mungkin akan cukup banyak perubahan di sisi Chatbot
- Perubahannya misal parsing data yang sebelumnya dari WA disini dari Qiscus
- Keuntungannya Agent bisa outbound message, follow up ke customer.
- Mengimplementasikan Custom Agent allocation untuk assgin agent based on Division (https://documentation.qiscus.com/multichannel-customer-service/customization#custom-agent-allocation)
 - Custom channel yang akan allocate Agent dengan data yang didapat dari Chatbot (comment extra: mapel+kelas, room_id)


## Qiscus send another data to our logger
```plantuml
wabiz -> qiscus
qiscus -> logger: webhook: log incoming
qiscus -> logger: webhook: log outgoing
qiscus -> wabiz
```

## Catch resolve event and track the first comment in room
```plantuml
wabiz -> qiscus
qiscus -> chatbot: resolve event (contain agent's email and room id)
chatbot -> qiscus: get room detail by room id
qiscus --> chatbot: return room detail
chatbot -> chatbot: get the first and last agent comment timestamp
chatbot -> rlo: deduct coin based on first and last timestamp
qiscus --> wabiz
```

### Using inapp chat for teacher
```plantuml
actor user
entity "rg-chatbot-roboguru" as chatbot
entity "rlo-api" as rlo
actor teacher as teacher

user -> chatbot: Kelas 1 SMP Biologi
chatbot -> chatbot: <grade=kelas 1 SMP, subject=Biologi>
chatbot --> user: Silakan ketik pertanyaan yg kurang jelas?

user -> chatbot: Tanya tentang biologi
chatbot -> rlo: Match making user & teacher
rlo -> rlo: Lookup guru yg sesuai subject

rlo -> teacher: Notify teacher via push notif
teacher --> rlo: Confirm availability di app
rlo -> chatbot: Notify student for teacher availability
chatbot -> user: Notify student

teacher -> user: Halo murid, ada pertanyaan apa?
user -> teacher: Ini ada pertanyaan ....
teacher -> user: Sesi habis, mau lanjut lagi ga? Kalo mau lanjut ketik "LANJUT SESI"
user -> chatbot: LANJUT SESI
chatbot -> rlo: Check koin
rlo --> chatbot: Koin available
chatbot -> rlo: Deduct koin
teacher -> rlo: End conversation
rlo -> chatbot: End session
chatbot -> chatbot: Change state to "input rating guru"
user -> chatbot: End conversation
chatbot -> rlo: End session
chatbot -> chatbot: Change state to "input rating guru"

```

- [x] Record semua 2 way conversation
- [x] Agent ID
- [x] Bisa matching ke teacher untuk subject tertentu
- [x] Record start chat & end chat -> untuk penggajian
- [x] Multiple phone number
- [x] Only one agent can handle a single conversation


Conversation
- Realtime*
- Non realtime

Conclusion
- Use new account, new dashboard, different agents
- Multiple phone number can be ingested to the same dashboard
- Qiscus to discuss internally how to handle 3 unchecked requirements above


## Internal
```plantuml
actor user
entity "rlo-api" as rlo
entity "rg-chatbot-roboguru" as chat
entity "rg-user" as rguser
entity qiscus as qiscus
entity logger

user -> chat: Tanya soal
chat -> rguser: Lookup userID by phone
rguser --> chat: userID
chat -> rlo: check coin
rlo --> chat: coin available
chat -> user: Please wait
chat -> qiscus: looking for teacher
qiscus --> chat: response teacher
chat -> rlo: start session
rlo -> rlo: deduct coin
user -> chat: Berapa luas lingkaran?
chat -> qiscus: Berapa luas lingkaran?
qiscus -> chat: Tergantung jari2nya
chat --> user
qiscus -> logger: send webhook event
logger -> rlo: store chat
qiscus -> chat: end chat
chat -> rlo: end session
rlo -> rlo: decide to rollback or not
```


## Questions
- Student ask to different Roboguru number at the same time, different subject
    - Decision: Use the same state across multiple number
- Bisa ngeban
    - Decision: gak bisa
- given koin cuma 1, kalau nanya di app terus nanya di WA, bisa data race?
    - Decision: sekarang bisa, need discus with team rlo
    - Proposal: Deduct coin when start looking for teacher & will be refund if condition not meet

## notes
- messaging team handle things related to chatbot-qiscus communication
- roboguru team handle things related to chatbot-rlo communication
- roboguru team need to discuss how to handle rlo-coin in app with rlo team
- messaging team will push our recently discussed idea to qiscus
- need to find where to save conversation log


## feedback and questions for WA flow
Link: [spreadsheet](https://docs.google.com/spreadsheets/d/10nNXM0qwiraLcepHpvqa8dSrw2J6XjSH9nvTQzslBns/edit#gid=0)
- for all states, what to do given invalid input? repeat the mesage with same wording or no? (there is exist a state that give different wording when given invalid input by user)
- need confirm, which one is the source of truth? `Message` or`Message (Edited)`?
- should we inform user about which RG account that this number is associated with
- it seems column `Next State` is not yet completed. 
- 
- row 10: RootRLO
    - cara kembali ke start roboguru pakai `ROBO` sedangkan banyak yang lain pakai keyword `belajar`, apa bisa dibuat uniform aja?
- row 11: PurchaseCoin
    - pilihan beli koin yang mana ga ditaro di web/deeplink aja kah?
- row 21, 22: Question, TutorMatchmaking
    - immediately change state from Question or waiting for input?
    - can we make put this two things in one state?
- row 25, 27: LearningSession, ContinueLearning
    - how can student terminate session?
- row 26: FinishLearning
    - need confirmation: it is now written `Lanjut = LearningSession`. perhaps it was supposed to be ContinueLearning instead of LearningSession?
    - is there a timeout for user so that he can't continue learning with previous tutor?
- row 27: ContinueLearning
    - should we inform user about their remaining coin?
- row 29: ContinueLearningNoCoin
    - what state and what input makes the user go into this state

## APIs
### RLO api
    