Test ortamında OTPMOCK_URL=https://api.otpmock.com tanımlayın, Bird (MessageBird) istemcisini bu adrese yönlendirin ve Bird (MessageBird) kimlik bilgisi olarak otpmock API anahtarınızı kullanın. Uygulama kodunuz değişmez; canlı ortam Bird (MessageBird) ile göndermeye devam eder.
Kurulum
Resmi SDK'nın, anahtardan türetilen bölge adresini geçersiz kılan bir baseUrl seçeneği var.
import { BirdClient } from "@messagebird/sdk";
export const bird = new BirdClient({
apiKey: process.env.BIRD_API_KEY, // testte: otpmock API anahtarı
...(process.env.OTPMOCK_URL && { baseUrl: process.env.OTPMOCK_URL }),
});import os
import requests
BIRD_URL = os.environ.get("OTPMOCK_URL", "https://us-west-1.platform.bird.com")
requests.post(
f"{BIRD_URL}/v1/sms/messages",
headers={"Authorization": f"Bearer {os.environ['BIRD_API_KEY']}"}, # testte: otpmock API anahtarı
json={"from": "+15557654321", "to": "+15550142", "text": f"Your code is {code}", "category": "authentication"},
).raise_for_status()// Bird has no Java SDK; call the REST API and swap the host.
String base = System.getenv().getOrDefault("OTPMOCK_URL", "https://eu.platform.bird.com");
HttpRequest req = HttpRequest.newBuilder(URI.create(base + "/v1/sms/messages"))
.header("Authorization", "Bearer " + System.getenv("BIRD_API_KEY")) // testte: otpmock API anahtarı
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(json)) // {"from":"+1...","to":"+1...","text":"...","category":"authentication"}
.build();// Bird has no official .NET SDK; call the REST API with HttpClient.
var birdUrl = Environment.GetEnvironmentVariable("OTPMOCK_URL") ?? "https://eu-west-1.platform.bird.com";
var http = new HttpClient { BaseAddress = new Uri(birdUrl) };
http.DefaultRequestHeaders.Add("Authorization",
"Bearer " + Environment.GetEnvironmentVariable("BIRD_API_KEY")); // testte: otpmock API anahtarı
await http.PostAsJsonAsync("/v1/sms/messages",
new { from = "+15557654321", to = phone, text = $"Your code is {code}", category = "authentication" });use GuzzleHttp\Client;
$birdUrl = getenv('OTPMOCK_URL') ?: 'https://us-west-1.platform.bird.com';
(new Client())->post("$birdUrl/v1/sms/messages", [
'headers' => ['Authorization' => 'Bearer ' . getenv('BIRD_API_KEY')], // testte: otpmock API anahtarı
'json' => ['from' => '+15557654321', 'to' => '+15550142', 'text' => "Your code is $code", 'category' => 'authentication'],
]);require "net/http"
require "json"
# Bird has no official Ruby SDK; apps call the REST API, so only the host changes.
BIRD_URL = ENV.fetch("OTPMOCK_URL", "https://api.bird.com")
res = Net::HTTP.post(
URI("#{BIRD_URL}/v1/sms/messages"),
{ from: "+15557654321", to: "+15550142", text: "Your code is #{code}", category: "authentication" }.to_json,
"Content-Type" => "application/json",
"Authorization" => "Bearer #{ENV["BIRD_API_KEY"]}" # testte: otpmock API anahtarı
)// Bird has no official Go SDK; call its HTTP API with net/http, only the host changes.
base := os.Getenv("OTPMOCK_URL")
if base == "" {
base = "https://eu.platform.bird.com"
}
body, _ := json.Marshal(map[string]any{"from": os.Getenv("BIRD_NUMBER"), "to": "+15550142", "text": msg, "category": "authentication"})
req, _ := http.NewRequest("POST", base+"/v1/sms/messages", bytes.NewReader(body))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer "+os.Getenv("BIRD_API_KEY")) // testte: otpmock API anahtarı
res, err := http.DefaultClient.Do(req) // 202, status "accepted"Her dil, CI'da sağlayıcının resmi SDK'sıyla (ya da başka bir adrese yönlendirilemeyen SDK'larda düz HTTP API'siyle) otpmock'a karşı sınanır.
Kimlik bilgisi. Test ortamında Bird API anahtarı değişkeninizi otpmock API anahtarınıza çevirin. baseUrl ayarlıyken SDK artık bk_{region}_ anahtar önekini aramaz.
otpmock neyi taklit ediyor?
| Uç nokta | Ne yapar |
|---|---|
POST /v1/sms/messages | Tek SMS gönderir (to, from, text, category), status: "accepted" ile 202 |
POST /v1/verify/verifications | Verify: başlatır (kodu otpmock üretir; options.code_length dikkate alınır; aynı numara için açık bir doğrulama varsa yeniden kullanılır) |
POST /v1/verify/verifications/check | Verify: alıcıya göre kontrol eder; success, reason (incorrect_code, attempts_exhausted) ve attempts_remaining ile 200 |
POST /v1/verify/verifications/next-channel | Verify: aynı kodu SMS ile yeniden gönderir |
Yanıtlar ve hatalar Bird (MessageBird) API'sinin kendi biçimindedir, bu yüzden istemci kütüphanesi onları her zamanki gibi çözümler. Yanlış anahtar ve aylık hakkın dolması da aynı hata biçimiyle döner.
Telefon numaraları
E.164 biçiminde (+15550142) gönderin, Bird da böyle bekler.
Testinizde kodu okuyun
const telefon = otp.randomPhone(); // her test için ayrı numara
const since = Date.now() - 5_000;
await page.getByRole("button", { name: "Kod gönder" }).click(); // uygulamanız Bird (MessageBird) API'sini çağırır
const { code } = await otp.waitForCode(telefon, { since });otp yardımcısı bağımlılığı olmayan tek bir dosyadır: dokümandan alın (İngilizce). Baştan sona örnekler: Playwright ve Cypress rehberleri (İngilizce).
Bilmeniz gerekenler
- Bu, Bird'ün güncel SMS API'sidir. Eski MessageBird API'si (
rest.messagebird.com/messages) ve eskimessagebirdnpm paketi taklit edilmez: o SDK başka bir adrese yönlendirilemez. - Aylık hak bittiğinde otpmock, hız sınırı hatası yerine Bird'ün
billing_error(402) hatasını döner; böylece SDK döngüde yeniden denemez.
Sık sorulanlar
otpmock Bird (MessageBird) üzerinden gerçek SMS gönderiyor mu?
Hayır. Test ortamında uygulamanızın Bird (MessageBird) istekleri otpmock'a gider; mesaj 10 dakika saklanır ve Bird (MessageBird) ya da herhangi bir operatör ağına hiç ulaşmaz. Canlı ortamınız Bird (MessageBird) kullanmaya devam eder, çünkü otpmock yalnızca OTPMOCK_URL tanımlıyken devreye girer.
Resmi @messagebird/sdk SDK'sı destekleniyor mu?
Evet. Bird (MessageBird) uç noktaları, resmi @messagebird/sdk paketiyle Node.js'te uçtan uca sınanır. Adres değiştirmeye izin veren başka dillerdeki istemciler de çalışır.
otpmock hangi Bird (MessageBird) API'lerini destekliyor?
POST /v1/sms/messages (Tek SMS gönderir (to, from, text, category), status: "accepted" ile 202); POST /v1/verify/verifications (Verify: başlatır (kodu otpmock üretir; options.code_length dikkate alınır; aynı numara için açık bir doğrulama varsa yeniden kullanılır)); POST /v1/verify/verifications/check (Verify: alıcıya göre kontrol eder; success, reason (incorrect_code, attempts_exhausted) ve attempts_remaining ile 200); POST /v1/verify/verifications/next-channel (Verify: aynı kodu SMS ile yeniden gönderir).
Ücretsiz plan ayda 300 mesaj içerir, kart gerekmez. Yapay zeka kodlama asistanı mı kullanıyorsunuz? otpmock.com/llms-full.txt adresini verin.
Ücretsiz API anahtarı al