-
Notifications
You must be signed in to change notification settings - Fork 0
/
render.html
126 lines (101 loc) · 2.68 KB
/
render.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<html>
<body style='text-align:center; font-family:Lucida Sans'>
<br><b>PHOTO OVER SMS</b><br>
<input id="ac" type='text' placeholder='TWILIO ACCOUNT SID'><br>
<input id="to" type='password' placeholder='TWILIO TOKEN'><br>
<input id="pn" type='text' placeholder='TWILIO PHONE (+XXX...)'><br>
<div id='get'>GO!</div>
<div id='progress'></div>
<div id='myimgs' style='margin-top:50px'></div>
</body>
<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<script>
$('#get').on('click', function(e)
{
var pn = $('#pn').val().trim() // Twilio phone number
var ac = $('#ac').val().trim()
var to = $('#to').val().trim()
//next_page_uri
var txt = [];
var next_uri = 'https://api.twilio.com/2010-04-01/Accounts/'+ac+'/Messages.json?PageSize=20&To='+pn;
function get_txt ()
{
//console.log(txt)
$('#progress').text($('#progress').text() + '*')
setTimeout(function()
{
console.log('start request')
var request = new XMLHttpRequest();
request.open("GET", next_uri, false);
request.setRequestHeader("Authorization", authenticateUser(ac, to));
request.send();
console.log('end request')
// view request status
var resp = JSON.parse(request.response)
//console.log(request)//.messages);
var m = resp.messages
for (var i=0; i<m.length; ++i)
{
//console.log(m[i].body)
if (m[i].body.substr(0,1) == '#')
{
txt.push(m[i].body)
}
}
//console.log(resp)
if (resp.next_page_uri == null)
{
console.log('end')
callback()
}
else
{
console.log('go ahead')
next_uri = 'https://api.twilio.com' + resp.next_page_uri
get_txt()
}
}, 1000)
}
$('#progress').text('')
get_txt()
function callback()
{
var txv = {}
var M = {}
for (j=0; j<txt.length; ++j)
{
var txu = txt[j].split('#')
if (txv[txu[1]] == null)
{
txv[txu[1]] = {}
}
txv[txu[1]][txu[2]] = txu[4]
M[txu[1]] = txu[3];
}
var f = {};
var html = ''
for (k in txv)
{
console.log(k)
if (txv.hasOwnProperty(k))
{
var f = ''
for (var m=0; m<M[k]; ++m)
{
f += txv[k][m];
}
}
html += "<img style='transform:rotate(90deg)' src='" + f + "'>"
}
$('#myimgs').html(html)
// could add error correction
}
})
function authenticateUser(user, password)
{
var token = user + ":" + password;
var hash = btoa(token);
return "Basic " + hash;
}
</script>
</html>