@@ -202,6 +202,67 @@ func TestServer_Twilio_Call_Success_With_Yes(t *testing.T) {
202
202
})
203
203
}
204
204
205
+ func TestServer_Twilio_Call_Success_with_custom_twiml (t * testing.T ) {
206
+ var called atomic.Bool
207
+ twilioServer := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
208
+ if called .Load () {
209
+ t .Fatal ("Should be only called once" )
210
+ }
211
+ body , err := io .ReadAll (r .Body )
212
+ require .Nil (t , err )
213
+ require .Equal (t , "/2010-04-01/Accounts/AC1234567890/Calls.json" , r .URL .Path )
214
+ require .Equal (t , "Basic QUMxMjM0NTY3ODkwOkFBRUFBMTIzNDU2Nzg5MA==" , r .Header .Get ("Authorization" ))
215
+ require .Equal (t , "From=%2B1234567890&To=%2B11122233344&Twiml=%0A%3CResponse%3E%0A%09%3CPause+length%3D%221%22%2F%3E%0A%09%3CSay+language%3D%22de-DE%22+loop%3D%223%22%3E%0A%09%09Du+hast+eine+Nachricht+von+notify+im+Thema+mytopic.+Nachricht%3A%0A%09%09%3Cbreak+time%3D%221s%22%2F%3E%0A%09%09hi+there%0A%09%09%3Cbreak+time%3D%221s%22%2F%3E%0A%09%09Ende+der+Nachricht.%0A%09%09%3Cbreak+time%3D%221s%22%2F%3E%0A%09%09Diese+Nachricht+wurde+von+Benutzer+phil+gesendet.+Sie+wird+drei+Mal+wiederholt.%0A%09%09Um+dich+von+Anrufen+wie+diesen+abzumelden%2C+entferne+deine+Telefonnummer+in+der+notify+web+app.%0A%09%09%3Cbreak+time%3D%223s%22%2F%3E%0A%09%3C%2FSay%3E%0A%09%3CSay+language%3D%22de-DE%22%3EAuf+Wiederh%C3%B6ren.%3C%2FSay%3E%0A%3C%2FResponse%3E" , string (body ))
216
+ called .Store (true )
217
+ }))
218
+ defer twilioServer .Close ()
219
+
220
+ c := newTestConfigWithAuthFile (t )
221
+ c .TwilioCallsBaseURL = twilioServer .URL
222
+ c .TwilioAccount = "AC1234567890"
223
+ c .TwilioAuthToken = "AAEAA1234567890"
224
+ c .TwilioPhoneNumber = "+1234567890"
225
+ c .TwilioCallFormat = `
226
+ <Response>
227
+ <Pause length="1"/>
228
+ <Say language="de-DE" loop="3">
229
+ Du hast eine Nachricht von notify im Thema %s. Nachricht:
230
+ <break time="1s"/>
231
+ %s
232
+ <break time="1s"/>
233
+ Ende der Nachricht.
234
+ <break time="1s"/>
235
+ Diese Nachricht wurde von Benutzer %s gesendet. Sie wird drei Mal wiederholt.
236
+ Um dich von Anrufen wie diesen abzumelden, entferne deine Telefonnummer in der notify web app.
237
+ <break time="3s"/>
238
+ </Say>
239
+ <Say language="de-DE">Auf Wiederhören.</Say>
240
+ </Response>`
241
+ s := newTestServer (t , c )
242
+
243
+ // Add tier and user
244
+ require .Nil (t , s .userManager .AddTier (& user.Tier {
245
+ Code : "pro" ,
246
+ MessageLimit : 10 ,
247
+ CallLimit : 1 ,
248
+ }))
249
+ require .Nil (t , s .userManager .AddUser ("phil" , "phil" , user .RoleUser ))
250
+ require .Nil (t , s .userManager .ChangeTier ("phil" , "pro" ))
251
+ u , err := s .userManager .User ("phil" )
252
+ require .Nil (t , err )
253
+ require .Nil (t , s .userManager .AddPhoneNumber (u .ID , "+11122233344" ))
254
+
255
+ // Do the thing
256
+ response := request (t , s , "POST" , "/mytopic" , "hi there" , map [string ]string {
257
+ "authorization" : util .BasicAuth ("phil" , "phil" ),
258
+ "x-call" : "+11122233344" ,
259
+ })
260
+ require .Equal (t , "hi there" , toMessage (t , response .Body .String ()).Message )
261
+ waitFor (t , func () bool {
262
+ return called .Load ()
263
+ })
264
+ }
265
+
205
266
func TestServer_Twilio_Call_UnverifiedNumber (t * testing.T ) {
206
267
c := newTestConfigWithAuthFile (t )
207
268
c .TwilioCallsBaseURL = "http://dummy.invalid"
0 commit comments