Having a tough time writing Gateway module

Events happening in the community are now at Drupal community events on www.drupal.org.
ethant's picture

Sorry guys, but I'm a dummy. I've tried to create a module for the eztexting gateway (http://www.eztexting.com/developers/), and have not been succesful. Can anyone tell me what I'm doing wrong? Thanks in advance.

<?php
// $Id: sms_eztexting.module,v 1.4.2.3 2008/10/09 17:26:25 diggersf Exp $

/**
* @file
* Adds support for sending SMS messages using the EZTexting gateway.
*/

/**
* Implementation of hook_gateway_info().
*/
function sms_eztexting_gateway_info() {
return array(
'sms_eztexting_gateway' => array(
'name' => 'EZ Texting',
'send' => 'sms_eztexting_send',
'receive' => TRUE,
'configure form' => 'sms_eztexting_admin_form',
'send form' => 'sms_eztexting_send_form',
),
);
}

$form['sms_eztexting_ssl'] = array(
'#type' => 'checkbox',
'#title' => t('Use SSL Encyption'),
'#description' => t('Drupal\'s built-in HTTP client only supports SSL on PHP 4.3 compiled with OpenSSL.'),
'#default_value' => $configuration['sms_eztexting_ssl'],
);

function sms_eztexting_admin_form($configuration) {
$form['sms_eztexting_user'] = array(
'#type' => 'textfield',
'#title' => t('User'),
'#description' => t('The username of your EZ Texting account.'),
'#size' => 40,
'#maxlength' => 255,
'#default_value' => $configuration['sms_eztexting_user'],
);

$form['sms_eztexting_password'] = array(
'#type' => 'textfield',
'#title' => t('Pass'),
'#description' => t('The current password on your EZ Texting account.'),
'#size' => 30,
'#maxlength' => 64,
'#default_value' => $configuration['sms_eztexting_password'],
);

return $form;
}

/**
* Returns custom additions to be added to the send forms
*/
function sms_eztexting_send_form() {
$form['country'] = array(
'#type' => 'select',
'#title' => t('Country'),
'#multiple' => FALSE,
'#options' => sms_eztexting_country_codes(FALSE),
'#default_value' => -1,
);
return $form;
}

function sms_eztexting_send($number, $message, $options) {
$number = $options['Country'] . $number;
return sms_eztexting_command('sendmsg', array('PhoneNumber' => $number, 'Message' => $message));
}
{

if ($config == NULL) {
$config = $gateway['configuration'];
}

if ($config['sms_eztexting_ssl']) {
$scheme = 'https';
}
else {
$scheme = 'http';
}

$http_result = drupal_http_request($scheme .'://app.eztexting.com/api/sending/'. $command .'?'. $query);
}

function sms_eztexting_country_codes() {
return array(
93 => "Afghanistan",
355 => "Albania",
213 => "Algeria",
376 => "Andorra",
244 => "Angola",
1264 => "Anguilla",
1268 => "Antigua & Barbuda",
54 => "Argentina",
374 => "Armenia",
297 => "Aruba",
61 => "Australia",
43 => "Austria",
994 => "Azerbaijan",
1242 => "Bahamas",
973 => "Bahrain",
880 => "Bangladesh",
1246 => "Barbados",
375 => "Belarus",
32 => "Belgium",
501 => "Belize",
229 => "Benin",
1441 => "Bermuda",
975 => "Bhutan",
591 => "Bolivia",
387 => "Bosnia-Herzegovina",
267 => "Botswana",
55 => "Brazil",
1284 => "British Virgin Islands",
673 => "Brunei",
359 => "Bulgaria",
226 => "Burkina Faso",
257 => "Burundi",
855 => "Cambodia",
237 => "Cameroon",
34 => "Canary Islands",
238 => "Cape Verde",
1345 => "Cayman Islands",
236 => "Central African Republic",
235 => "Chad",
56 => "Chile",
86 => "China",
57 => "Colombia",
269 => "Comoros",
242 => "Congo",
243 => "Democratic Republic Congo",
682 => "Cook Islands",
385 => "Croatia",
53 => "Cuba",
357 => "Cyprus",
420 => "Czech Republic",
45 => "Denmark",
253 => "Djibouti",
1767 => "Dominica",
670 => "East Timor",
593 => "Ecuador",
20 => "Egypt",
503 => "El Salvador",
240 => "Equatorial Guinea",
372 => "Estonia",
251 => "Ethiopia",
500 => "Falkland Islands",
298 => "Faroe Islands",
679 => "Fiji",
358 => "Finland",
33 => "France",
594 => "French Guiana",
689 => "French Polynesia",
241 => "Gabon",
220 => "Gambia",
995 => "Georgia",
49 => "Germany",
233 => "Ghana",
350 => "Gibraltar",
881 => "Global Mobile Satellite",
30 => "Greece",
299 => "Greenland",
1473 => "Grenada",
590 => "Guadeloupe",
1671 => "Guam",
502 => "Guatemala",
224 => "Guinea",
592 => "Guyana",
509 => "Haiti",
504 => "Honduras",
852 => "HongKong",
36 => "Hungary",
354 => "Iceland",
91 => "India",
62 => "Indonesia",
98 => "Iran",
964 => "Iraq",
353 => "Ireland",
972 => "Israel",
39 => "Italy / Vatican City State",
225 => "Ivory Coast",
1876 => "Jamaica",
81 => "Japan",
962 => "Jordan",
254 => "Kenya",
82 => "Korea (South)",
965 => "Kuwait",
996 => "Kyrgyzstan",
856 => "Lao",
371 => "Latvia",
961 => "Lebanon",
266 => "Lesotho",
231 => "Liberia",
218 => "Libya",
423 => "Liechtenstein",
370 => "Lithuania",
352 => "Luxembourg",
853 => "Macau",
389 => "Macedonia",
261 => "Madagascar",
265 => "Malawi",
60 => "Malaysia",
960 => "Maldives",
223 => "Mali",
356 => "Malta",
596 => "Martinique",
222 => "Mauritania",
230 => "Mauritius",
269 => "Mayotte Island (Comoros)",
52 => "Mexico",
373 => "Moldova",
377 => "Monaco (Kosovo)",
976 => "Mongolia",
382 => "Montenegro",
1664 => "Montserrat",
212 => "Morocco",
258 => "Mozambique",
95 => "Myanmar",
264 => "Namibia",
977 => "Nepal",
31 => "Netherlands",
599 => "Netherlands Antilles",
687 => "New Caledonia",
64 => "New Zealand",
505 => "Nicaragua",
227 => "Niger",
234 => "Nigeria",
47 => "Norway",
968 => "Oman",
92 => "Pakistan",
970 => "Palestine (+970)",
9725 => "Palestine (+9725)",
507 => "Panama",
675 => "Papua New Guinea",
595 => "Paraguay",
51 => "Peru",
63 => "Philippines",
48 => "Poland",
351 => "Portugal",
974 => "Qatar",
262 => "Reunion",
40 => "Romania",
7 => "Russia / Kazakhstan",
250 => "Rwanda",
1670 => "Saipan",
1684 => "Samoa (American)",
685 => "Samoa (Western)",
378 => "San Marino",
882 => "Satellite-Thuraya",
966 => "Saudi Arabia",
221 => "Senegal",
381 => "Serbia",
248 => "Seychelles",
232 => "Sierra Leone",
65 => "Singapore",
421 => "Slovakia",
386 => "Slovenia",
252 => "Somalia",
27 => "South Africa",
34 => "Spain",
94 => "Sri Lanka",
1869 => "St. Kitts And Nevis",
1758 => "St. Lucia",
1784 => "St. Vincent",
249 => "Sudan",
597 => "Suriname",
268 => "Swaziland",
46 => "Sweden",
41 => "Switzerland",
963 => "Syria",
886 => "Taiwan",
992 => "Tajikistan",
255 => "Tanzania",
66 => "Thailand",
228 => "Togo",
676 => "Tonga Islands",
1868 => "Trinidad and Tobago",
216 => "Tunisia",
90 => "Turkey",
993 => "Turkmenistan",
1649 => "Turks and Caicos Islands",
256 => "Uganda",
44 => "UK / Isle of Man / Jersey / Guernsey",
380 => "Ukraine",
971 => "United Arab Emirates",
598 => "Uruguay",
1 => "USA / Canada / Dominican Rep. / Puerto Rico",
998 => "Uzbekistan",
678 => "Vanuatu",
58 => "Venezuela",
84 => "Vietnam",
967 => "Yemen",
260 => "Zambia",
255 => "Zanzibar",
263 => "Zimbabwe",
);
}

Comments

Hi Ethan, I'm also in the

andy_read's picture

Hi Ethan,

I'm also in the process of writing an SMS gateway for AQL.com. I may not have all of the answers, but I'm prepared to "share the pain" :-)

Could you tell us what you've done to test your gateway and in what sense you "have not been successful", i.e. what does happen or does not do what you expect?

On my work so far I've only been working on inbound SMS and although I'm correctly receiving SMS messages and even re-assembling multi-SMS messages, the SMS framework doesn't seem to give me the option to do anything useful with it! The only 'action' requires a keyword, but I have a dedicated SMS number so no keyword is required or wanted for my application.

Certain bits of this process leave me feeling that there should be more generic functions in the framework e.g. for re-assembling multi-part messages or for long list of country codes that you've included above.

Hey Andy

ethant's picture

I'm able to configure my module (in SMS Framework) without it erroring out, but when I create a front end "user" account, I'm able to register my number, details, etc, but I do not receive a confirmation code (via text). So, I'm not successfully "pushing" to the gateway.

Kudos to you - at least you've made some kind of a connection!

Send form test?

andy_read's picture

I'm not sure how the configuration needs to be set for user registration.

Have you tried the simplest of test using the send form?

My usual approach to debugging is inserting watchdog or drupal_set_message calls into the code to trace through where it's doing what you expect and where it's going wrong.

Hey Andy. Do you mean

ethant's picture

Hey Andy. Do you mean sending via the html / php form combo (outside of Drupal environment)? I was successful going at it this way.

'send form' entry in hook_gateway_info()

andy_read's picture

Hi Ethan,

Sorry my comment was not completely thought through and may have been unhelpful.
I don't know what you're referring to by "html / php form combo".

I'm aware of an entry in the gateway_info hook for a 'send_form'. I had found this in the mobivity gateway, which I've been using as a template. I had assumed that this created a form for freely sending SMS messages, but now having looked further I see that the sms_mobivity_send_form() function doesn't seem to be actually exist, so I'm not sure where the concept exists in reality. Maybe there's some other documentation elsewhere, but I haven't found it yet.

Anyway, I got my AQL gateway to send a verification SMS successfully from the user account mobility settings, so it seems to work in principle.

I don't have time in the next few days to try you code out and don't have any real reason to sign up for a eztexting account, so I would still advise that you trace the code using watchdog statements to find out where it's working and where it's going wrong. Or try using one of the php server debugger environments, but I've yet to get that sophisticated myself!

SMS Framework

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: