This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// src/app.ts | |
import express, { Router } from 'express'; | |
import callStateController from './controllers/call.state.controller'; | |
import * as path from 'path'; | |
const app = express(); | |
app.use(express.json()); | |
app.get('/', (req, res) => { | |
res.sendFile(path.join(process.env.PUBLIC_DIR as string, 'index.html')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Tiny CRM</title> | |
<style> | |
body { | |
padding: 10px; | |
font-size: 18px; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// src/call-state.controller.ts | |
import { Request, Response } from 'express'; | |
import CustomerModel from '../models/customer.model'; | |
import CallStateModel from '../models/call.state.model'; | |
import { emitCallStateChange } from '../socket'; | |
import moment from 'moment'; | |
const callStateController = { | |
handleNewCallState: async (req: Request, res: Response) => { | |
try { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// src/server.ts | |
import * as http from 'http'; | |
import dotenv from 'dotenv'; | |
import app from './app'; | |
import mongoose from 'mongoose'; | |
import { initSocketIo } from './socket'; | |
(async () => { | |
dotenv.config(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// src/socket.ts | |
import { Server } from 'socket.io'; | |
import * as http from 'http'; | |
let io: Server; | |
export function initSocketIo(server: http.Server) { | |
if (io) { | |
return; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// src/controllers/call-state.controller.ts | |
import { Request, Response } from 'express'; | |
import CustomerModel from '../models/customer.model'; | |
import CallStateModel from '../models/call.state.model'; | |
const callStateController = { | |
handleNewCallState: async (req: Request, res: Response) => { | |
try { | |
const { phone_number: phoneNumber, state, timestamp } = req.body; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// src/models/call-state.model.ts | |
import { Schema, Model, model, ObjectId } from 'mongoose'; | |
import CustomerModel from './customer.model'; | |
export enum CallState { | |
RINGING = 'RINGING', | |
OFFHOOK = 'OFFHOOK', | |
IDLE = 'IDLE', | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// src/models/customer.model.ts | |
import { Schema, Model, model } from 'mongoose'; | |
export interface ICustomer { | |
name: string; | |
phoneNumber: string; | |
} | |
const CustomerSchema = new Schema<ICustomer, Model<ICustomer>, ICustomer>({ | |
name: { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
package="io.codetheworld.tinycrm"> | |
<uses-permission android:name="android.permission.READ_PHONE_STATE" /> | |
<uses-permission android:name="android.permission.READ_CALL_LOG" /> | |
<uses-permission android:name="android.permission.INTERNET" /> | |
<application | |
android:allowBackup="true" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.codetheworld.tinycrm | |
import android.content.BroadcastReceiver | |
import android.content.Context | |
import android.content.Intent | |
import android.telephony.TelephonyManager | |
import android.util.Log | |
import okhttp3.MediaType.Companion.toMediaTypeOrNull | |
import okhttp3.RequestBody.Companion.toRequestBody | |
import org.json.JSONObject |