Skip to content

Commit

Permalink
Added SMS
Browse files Browse the repository at this point in the history
  • Loading branch information
robgruen committed Nov 2, 2024
1 parent 039ab87 commit 4b866c8
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 18 deletions.
4 changes: 2 additions & 2 deletions android/samples/mobile/.idea/deploymentTargetSelector.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class MainActivity : ComponentActivity() {
@Preview
fun Browser() {
val url = "http://10.0.2.2:3000"
//val url = "http://192.168.1.142:3000/"
var wvv: WebView? = null
var jsi: JavaScriptInterface? = null

Expand Down
5 changes: 2 additions & 3 deletions ts/packages/agentSdk/src/display.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ export type DisplayAppendMode = "inline" | "block" | "temporary";

export type ClientAction =
| "show-camera"
| "open-app"
| "show-notification"
| "start-intent"
| "set-alarm"
| "call-phonenumber";
| "call-phonenumber"
| "send-sms";

export interface ActionIO {
readonly type: DisplayType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
ActionResult,
} from "@typeagent/agent-sdk";
import { createActionResult } from "@typeagent/agent-sdk/helpers/action";
import { AndroidMobileAction, CallPhoneNumberAction, SetAlarmAction } from "./androidMobileSchema.js";
import { AndroidMobileAction, CallPhoneNumberAction, SendSMSAction, SetAlarmAction } from "./androidMobileSchema.js";

export function instantiate(): AppAgent {
return {
Expand Down Expand Up @@ -54,6 +54,12 @@ async function handlePhotoAction(
) {
let result: ActionResult | undefined = undefined;
switch (action.actionName) {
case "sendSMS": {
let smsAction = action as SendSMSAction;
result = createActionResult(`Sending SMS to ${smsAction.parameters.phoneNumber} message '${smsAction.parameters.message}'`);
context.actionIO.takeAction("send-sms", smsAction.parameters);
break;
}
case "callPhoneNumber": {
let callAction = action as CallPhoneNumberAction;
result = createActionResult(`Calling ${callAction.parameters.phoneNumber}`);
Expand All @@ -67,7 +73,7 @@ async function handlePhotoAction(
break;
}
default:
throw new Error(`Unknown action: ${action.actionName}`);
throw new Error(`Unknown action: ${action}`);
}
return result;
}
26 changes: 15 additions & 11 deletions ts/packages/agents/androidMobile/src/androidMobileSchema.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

export type AndroidMobileAction = CallPhoneNumberAction | SetAlarmAction | UnknownAction;
export type AndroidMobileAction = SendSMSAction | CallPhoneNumberAction | SetAlarmAction;

// sends a SMS to the supplied phone number
export type SendSMSAction = {
actionName: "sendSMS",
parameters: {
// the original request of the user
originalRequest: string;
// the phone number to message
phoneNumber: string;
// the sms message
message: string;
}
}

// calls a user's phone number but only if we know the phone number
export type CallPhoneNumberAction = {
Expand All @@ -23,13 +36,4 @@ export type SetAlarmAction = {
// the time for the alarm in the format YYYY-mm-ddThh:mm:ss (i.e. 2024-02-15T08:30:15 )
time: string;
};
};

// if the user types text that can not easily be understood as a list action, this action is used
export interface UnknownAction {
actionName: "unknown";
parameters: {
// text typed by the user that the system did not understand
text: string;
};
}
};
5 changes: 5 additions & 0 deletions ts/packages/api/src/webServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ export class TypeAgentAPIWebServer {
this.server.listen(3000, "127.0.0.1", () => {
console.log("Listening on 127.0.0.1:3000");
});

// // starts a simple http server locally on port 3000
// this.server.listen(3000, "192.168.1.142", () => {
// console.log("Listening on 192.168.1.142:3000");
// });
}

stop() {
Expand Down
1 change: 1 addition & 0 deletions ts/packages/shell/src/lib/lib.android.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ declare var Android: {
showToast: (message: string) => void;
setAlarm: (time: string) => void;
callPhoneNumber: (phoneNumber: string) => void;
sendSMS: (phoneNumber: string, message: string) => void;
};
4 changes: 4 additions & 0 deletions ts/packages/shell/src/renderer/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ function addEvents(
let d: any = data;
Android?.callPhoneNumber(d.phoneNumber);
}
case "send-sms": {
let d: any = data;
Android.sendSMS(d.phoneNumber, d.message);
}
}
} catch (e) {
console.log(e);
Expand Down

0 comments on commit 4b866c8

Please sign in to comment.